Skip to content

Commit

Permalink
New naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
gusty committed Jan 24, 2024
1 parent 29d3ff3 commit 14578f0
Show file tree
Hide file tree
Showing 20 changed files with 539 additions and 503 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,42 @@
#r @"../../src/FSharpPlus/bin/Release/netstandard2.0/FSharpPlus.dll"

(**
Par-Applicative
===============
A functor with application, providing operations to embed pure expressions (``preturn``), parallel computations and combine their results (``</>``).
ZipApplicative
==============
A functor with application, providing operations to embed pure expressions (``pur``), run computations pointwise and/or paralell and combine their results (``<.>``).
___
Minimal complete definition
---------------------------
* ``preturn x`` &nbsp; / &nbsp; ``result x``
* ``(</>) f x``
* ``pur x`` &nbsp; . &nbsp; ``result x``
* ``(<.>) f x``
*)
(**
static member ParReturn (x: 'T) : 'Applicative<'T>
static member (</>) (f: 'Applicative<'T -> 'U>, x: 'Applicative<'T>) : 'Applicative<'U>
static member Pure (x: 'T) : 'ZipApplicative<'T>
static member (<.>) (f: 'ZipApplicative<'T -> 'U>, x: 'ZipApplicative<'T>) : 'ZipApplicative<'U>
*)
(**
Note: ``preturn`` can't be used outside computation expressions, use ``result`` instead.
Other operations
----------------
* ``plift2``
* ``zip``
*)
(**
static member ParLift2 (f: 'T1 -> 'T2 -> 'T, x1: 'Applicative<'T1>, x2: 'Applicative<'T2>) : 'Applicative<'T>
static member Zip (x1: 'ZipApplicative<'T1>, x2: 'ZipApplicative<'T2>) : 'ZipApplicative<'T1 * 'T2>
*)
(**
* ``map2``
*)
(**
static member Map2 (f: 'T1 -> 'T2 -> 'T, x1: 'ZipApplicative<'T1>, x2: 'ZipApplicative<'T2>) : 'ZipApplicative<'T>
*)

(**
* ``plift3``
* ``map3``
*)
(**
static member ParLift3 (f: 'T1 -> 'T2 -> 'T3 -> 'T, x1: 'Applicative<'T1>, x2: 'Applicative<'T2>, x3: 'Applicative<'T3>) : 'Applicative<'T>
static member Map3 (f: 'T1 -> 'T2 -> 'T3 -> 'T, x1: 'ZipApplicative<'T1>, x2: 'ZipApplicative<'T2>, x3: 'ZipApplicative<'T3>) : 'ZipApplicative<'T>
*)

(**
Expand All @@ -44,17 +49,17 @@ Rules
-----
*)
(**
presult id </> v = v
presult (<<) </> u </> v </> w = u </> (v </> w)
presult f <*> presult x = presult (f x)
u <*> presult y = presult ((|>) y) </> u
pur id <.> v = v
pur (<<) <.> u <.> v <.> w = u <.> (v <.> w)
pur f <*> pur x = pur (f x)
u <*> pur y = pur ((|>) y) <.> u
*)
(**
Related Abstractions
--------------------
- [Functor](abstraction-functor.html): A parallel applicative is a functor whose ``map`` operation can be splitted in ``preturn`` and ``(</>)`` operations,
- [Functor](abstraction-functor.html): A zipApplicative is a functor whose ``map`` operation can be splitted in ``pur`` and ``(<.>)`` operations,
- [Applicative](abstraction-applicative.html) : Parallel Applicatives are applicatives which usually don't form a [Monad](abstraction-monad.html).
- [ZipApplicative](abstraction-applicative.html) : ZipApplicatives are applicatives which usually don't form a [Monad](abstraction-monad.html).
Concrete implementations
------------------------
Expand All @@ -81,7 +86,7 @@ From F#+
- [``NonEmptySeq<'T>``]
- [``NonEmptyList<'T>``](type-nonempty.html)
- [``Compose<'Applicative1<'Applicative2<'T>>>``](type-compose.html)
- [``Compose<'ZipApplicative1<'ZipApplicative2<'T>>>``](type-compose.html)
(*) The operation is the same as that for the normal applicative
Expand Down Expand Up @@ -114,15 +119,15 @@ open FSharpPlus
// pointwise operations

let arr1 = (+) <!> [|1;2;3|] <*> [|10;20;30|]
let arr2 = (+) <!> [|1;2;3|] </> [|10;20;30|]
let arr2 = (+) <!> [|1;2;3|] <.> [|10;20;30|]

// val arr1: int array = [|11; 21; 31; 12; 22; 32; 13; 23; 33|]
// val arr2: int array = [|11; 22; 33|]


// Validations

let validated = par2 {
let validated = zapp2 {
let! x = async { return Ok 1 }
and! y = async { return Ok 2 }
and! z = async { return Error ["Error"] }
Expand Down
34 changes: 17 additions & 17 deletions src/FSharpPlus/Builders.fs
Original file line number Diff line number Diff line change
Expand Up @@ -210,24 +210,24 @@ module GenericBuilders =
member _.Run x : '``Applicative1<Applicative2<Applicative3<'T>>>`` = x


/// Generic Parallel Applicative CE builder.
type ParallelBuilder<'``applicative<'t>``> () =
/// Generic ZipApplicative CE builder.
type ZipApplicativeBuilder<'``applicative<'t>``> () =
member _.ReturnFrom (expr) = expr : '``applicative<'t>``
member inline _.Return (x: 'T) = ParReturn.Invoke x : '``Applicative<'T>``
member inline _.Yield (x: 'T) = ParReturn.Invoke x : '``Applicative<'T>``
member inline _.Return (x: 'T) = pur x : '``Applicative<'T>``
member inline _.Yield (x: 'T) = pur x : '``Applicative<'T>``
member inline _.BindReturn(x, [<InlineIfLambda>]f) = map f x : '``Applicative<'U>``
member inline _.MergeSources (t1: '``Applicative<'T>``, t2: '``Applicative<'U>``) : '``Applicative<'T * 'U>`` = ParLift2.Invoke tuple2 t1 t2
member inline _.MergeSources3 (t1: '``Applicative<'T>``, t2: '``Applicative<'U>``, t3: '``Applicative<'V>``) : '``Applicative<'T * 'U * 'V>`` = ParLift3.Invoke tuple3 t1 t2 t3
member _.Run f = f : '``Applicative<'T>``
member inline _.MergeSources (t1: '``Applicative<'T>``, t2: '``Applicative<'U>``) : '``Applicative<'T * 'U>`` = map2 tuple2 t1 t2
member inline _.MergeSources3 (t1: '``Applicative<'T>``, t2: '``Applicative<'U>``, t3: '``Applicative<'V>``) : '``Applicative<'T * 'U * 'V>`` = map3 tuple3 t1 t2 t3
member _.Run f : '``Applicative<'T>`` = f

/// Generic 2 layers Parallel Applicative CE builder.
type ParallelBuilder2<'``applicative1<applicative2<'t>>``> () =
/// Generic 2 layers ZipApplicative CE builder.
type ZipApplicativeBuilder2<'``applicative1<applicative2<'t>>``> () =
member _.ReturnFrom expr : '``applicative1<applicative2<'t>>`` = expr
member inline _.Return (x: 'T) : '``Applicative1<Applicative2<'T>>`` = (presult >> presult) x
member inline _.Yield (x: 'T) : '``Applicative1<Applicative2<'T>>`` = (presult >> presult) x
member inline _.Return (x: 'T) : '``Applicative1<Applicative2<'T>>`` = (pur >> pur) x
member inline _.Yield (x: 'T) : '``Applicative1<Applicative2<'T>>`` = (pur >> pur) x
member inline _.BindReturn (x: '``Applicative1<Applicative2<'T>>``, [<InlineIfLambda>]f: _ -> _) : '``Applicative1<Applicative2<'U>>`` = (map >> map) f x
member inline _.MergeSources (t1, t2) : '``Applicative1<Applicative2<'T>>`` = (plift2 >> plift2) tuple2 t1 t2
member inline _.MergeSources3 (t1, t2, t3) : '``Applicative1<Applicative2<'T>>`` = (plift3 >> plift3) tuple3 t1 t2 t3
member inline _.MergeSources (t1, t2) : '``Applicative1<Applicative2<'T>>`` = (map2 >> map2) tuple2 t1 t2
member inline _.MergeSources3 (t1, t2, t3) : '``Applicative1<Applicative2<'T>>`` = (map3 >> map3) tuple3 t1 t2 t3
member _.Run x : '``Applicative1<Applicative2<'T>>`` = x

/// Creates a (lazy) monadic computation expression with side-effects (see http://fsprojects.github.io/FSharpPlus/computation-expressions.html for more information)
Expand All @@ -245,10 +245,10 @@ module GenericBuilders =
/// Creates an applicative computation expression which compose effects of three Applicatives.
let applicative3<'``Applicative1<Applicative2<Applicative3<'T>>>``> = ApplicativeBuilder3<'``Applicative1<Applicative2<Applicative3<'T>>>``> ()

/// Creates a parallel applicative computation expression.
let par<'``Applicative<'T>``> = ParallelBuilder<'``Applicative<'T>``> ()
/// Creates a (non sequential) applicative computation expression.
let zapp<'``Applicative<'T>``> = ZipApplicativeBuilder<'``Applicative<'T>``> ()

/// Creates a parallel applicative computation expression which compose effects of two Applicatives.
let par2<'``Applicative1<Applicative2<'T>>``> = ParallelBuilder2<'``Applicative1<Applicative2<'T>>``> ()
/// Creates a (non sequential) applicative computation expression which compose effects of two Applicatives.
let zapp2<'``Applicative1<Applicative2<'T>>``> = ZipApplicativeBuilder2<'``Applicative1<Applicative2<'T>>``> ()

#endif
12 changes: 6 additions & 6 deletions src/FSharpPlus/Control/Applicative.fs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ type Lift2 =
static member inline Lift2 (f, ((a: 'Monoid, x: 'T) , (b: 'Monoid, y: 'U) ), _mthd: Lift2) = Plus.Invoke a b, f x y
static member inline Lift2 (f, (struct (a: 'Monoid, x: 'T), struct (b: 'Monoid, y: 'U)), _mthd: Lift2) = struct (Plus.Invoke a b, f x y)
#if !FABLE_COMPILER
static member Lift2 (f, (x: Task<'T> , y: Task<'U> ), _mthd: Lift2) = Task.map2 f x y
static member Lift2 (f, (x: Task<'T> , y: Task<'U> ), _mthd: Lift2) = Task.lift2 f x y
#endif
#if !NET45 && !NETSTANDARD2_0 && !FABLE_COMPILER
static member Lift2 (f, (x: ValueTask<'T> , y: ValueTask<'U> ), _mthd: Lift2) = ValueTask.map2 f x y
static member Lift2 (f, (x: ValueTask<'T> , y: ValueTask<'U> ), _mthd: Lift2) = ValueTask.lift2 f x y
#endif
static member Lift2 (f, (x , y ), _mthd: Lift2) = Async.map2 f x y
static member Lift2 (f, (x , y ), _mthd: Lift2) = Async.lift2 f x y
static member Lift2 (f, (x , y ), _mthd: Lift2) = Option.map2 f x y

#if !FABLE_COMPILER
Expand Down Expand Up @@ -158,12 +158,12 @@ type Lift3 =
static member inline Lift3 (f, ((a: 'Monoid, x: 'T) , (b: 'Monoid, y: 'U) , (c: 'Monoid, z: 'U) ), _mthd: Lift3) = Plus.Invoke (Plus.Invoke a b) c, f x y z
static member inline Lift3 (f, (struct (a: 'Monoid, x: 'T), struct (b: 'Monoid, y: 'U), struct (c: 'Monoid, z: 'U)), _mthd: Lift3) = struct (Plus.Invoke (Plus.Invoke a b) c, f x y z)
#if !FABLE_COMPILER
static member Lift3 (f, (x: Task<'T> , y: Task<'U> , z: Task<'V> ), _mthd: Lift3) = Task.map3 f x y z
static member Lift3 (f, (x: Task<'T> , y: Task<'U> , z: Task<'V> ), _mthd: Lift3) = Task.lift3 f x y z
#endif
#if !NET45 && !NETSTANDARD2_0 && !FABLE_COMPILER
static member Lift3 (f, (x: ValueTask<'T> , y: ValueTask<'U> , z: ValueTask<'V> ), _mthd: Lift3) = ValueTask.map3 f x y z
static member Lift3 (f, (x: ValueTask<'T> , y: ValueTask<'U> , z: ValueTask<'V> ), _mthd: Lift3) = ValueTask.lift3 f x y z
#endif
static member Lift3 (f, (x , y , z ), _mthd: Lift3) = Async.map3 f x y z
static member Lift3 (f, (x , y , z ), _mthd: Lift3) = Async.lift3 f x y z
static member Lift3 (f, (x , y , z ), _mthd: Lift3) = Option.map3 f x y z

#if !FABLE_COMPILER
Expand Down
6 changes: 3 additions & 3 deletions src/FSharpPlus/Control/Functor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ type Zip =
static member Zip ((x: option<'T> , y: option<'U> , _output: option<'T*'U> ), _mthd: Zip) = Option.zip x y
static member Zip ((x: voption<'T> , y: voption<'U> , _output: voption<'T*'U> ), _mthd: Zip) = ValueOption.zip x y
static member Zip ((x: Result<'T, 'Error> , y: Result<'U, 'Error> , _output: Result<'T * 'U, 'Error> ), _mthd: Zip) = Result.zip x y
static member Zip ((x: Async<'T> , y: Async<'U> , _output: Async<'T*'U> ), _mthd: Zip) = Async.zip x y
static member Zip ((x: Async<'T> , y: Async<'U> , _output: Async<'T*'U> ), _mthd: Zip) = Async.zipSequentially x y
#if !FABLE_COMPILER
static member Zip ((x: Task<'T> , y: Task<'U> , _output: Task<'T*'U> ), _mthd: Zip) = Task.zip x y
static member Zip ((x: Task<'T> , y: Task<'U> , _output: Task<'T*'U> ), _mthd: Zip) = Task.zipSequentially x y
#endif
#if !NET45 && !NETSTANDARD2_0 && !FABLE_COMPILER
static member Zip ((x: ValueTask<'T> , y: ValueTask<'U> , _output: ValueTask<'T*'U> ), _mthd: Zip) = ValueTask.zip x y
static member Zip ((x: ValueTask<'T> , y: ValueTask<'U> , _output: ValueTask<'T*'U> ), _mthd: Zip) = ValueTask.zipSequentially x y
#endif

static member inline Invoke (source1: '``ZipFunctor<'T1>``) (source2: '``ZipFunctor<'T2>``) =
Expand Down
4 changes: 2 additions & 2 deletions src/FSharpPlus/Control/MonadOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module internal MonadOps =
let inline (>>=) x f = Bind.Invoke x f
let inline result x = Return.Invoke x
let inline (<*>) f x = Apply.Invoke f x
let inline presult x = ParReturn.Invoke x
let inline (</>) f x = ParApply.Invoke f x
let inline pur x = Pure.Invoke x
let inline (<.>) f x = ZipApply.Invoke f x
let inline (<|>) x y = Append.Invoke x y
let inline (>=>) (f: 'a->'``Monad<'b>``) (g: 'b->'``Monad<'c>``) (x: 'a) : '``Monad<'c>`` = f x >>= g

Expand Down
6 changes: 3 additions & 3 deletions src/FSharpPlus/Control/Monoid.fs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ type Plus with
#if !FABLE_COMPILER
type Plus with

static member inline ``+`` (x: 'a Task, y: 'a Task, [<Optional>]_mthd: Plus) = Task.map2 Plus.Invoke x y
static member inline ``+`` (x: 'a Task, y: 'a Task, [<Optional>]_mthd: Plus) = Task.lift2 Plus.Invoke x y
#endif

#if !NET45 && !NETSTANDARD2_0 && !FABLE_COMPILER
type Plus with

static member inline ``+`` (x: 'a ValueTask, y: 'a ValueTask, [<Optional>]_mthd: Plus) = ValueTask.map2 Plus.Invoke x y
static member inline ``+`` (x: 'a ValueTask, y: 'a ValueTask, [<Optional>]_mthd: Plus) = ValueTask.lift2 Plus.Invoke x y

#endif

Expand All @@ -138,7 +138,7 @@ type Plus with

static member inline ``+`` (f: 'T->'Monoid, g: 'T->'Monoid, [<Optional>]_mthd: Plus) = (fun x -> Plus.Invoke (f x) (g x)) : 'T->'Monoid

static member inline ``+`` (x: 'S Async , y: 'S Async , [<Optional>]_mthd: Plus) = Async.map2 Plus.Invoke x y
static member inline ``+`` (x: 'S Async , y: 'S Async , [<Optional>]_mthd: Plus) = Async.lift2 Plus.Invoke x y

static member inline ``+`` (x: 'a Expr , y: 'a Expr , [<Optional>]_mthd: Plus) : 'a Expr =
let inline f (x: 'a) : 'a -> 'a = Plus.Invoke x
Expand Down
Loading

0 comments on commit 14578f0

Please sign in to comment.