You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docsrc/content/computation-expressions.fsx
+3-16Lines changed: 3 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,9 @@ Computations Expressions
12
12
13
13
This library allows to use some common computation expressions without writing any boiler plate code.
14
14
15
-
There is a single computation expression: ``monad`` but it comes in 4 flavours:
15
+
For applicatives there is single computation expression: ``applicative { .. }``. Additionally ``applicative2 { .. }`` and ``applicative3 { .. }`` exists for composed (aka layered) applicatives.
16
+
17
+
For monadic code there is a single computation expression: ``monad { .. }`` but it comes in 4 flavours:
There are some F# issues preventing applicative required `BindReturn` to be included in `monad`, so for the moment the following snipped can be used to quickly create a generic applicative CE:
member inline_.Return(x:'T)= result x : '``Applicative<'T>``
186
+
member inline_.Yield(x:'T)= result x : '``Applicative<'T>``
187
+
member inline_.BindReturn(x,f)= map f x : '``Applicative<'U>``
188
+
member inline_.MergeSources(t1:'``Applicative<'T>``, t2: '``Applicative<'U>``):'``Applicative<'T*'U>`` = Lift2.Invoke tuple2 t1 t2
189
+
member inline_.MergeSources3(t1:'``Applicative<'T>``, t2: '``Applicative<'U>``,t3:'``Applicative<'V>``):'``Applicative<'T*'U*'V>`` = Lift3.Invoke tuple3 t1 t2 t3
member inline_.Return(x:'T):'``Applicative1<Applicative2<Applicative3<'T>>>`` =(result >> result >> result) x
206
+
member inline_.Yield(x:'T):'``Applicative1<Applicative2<Applicative3<'T>>>`` =(result >> result >> result) x
207
+
member inline_.BindReturn(x:'``Applicative1<Applicative2<Applicative3<'T>>>``,f:_ ->_):'``Applicative1<Applicative2<'U>>`` =(map >> map >> map) f x
208
+
member inline_.MergeSources(t1,t2):'``Applicative1<Applicative2<Applicative3<'T>>>`` =(lift2 >> lift2 >> lift2) tuple2 t1 t2
209
+
member inline_.MergeSources3(t1,t2,t3):'``Applicative1<Applicative2<Applicative3<'T>>>`` =(lift3 >> lift3 >> lift3) tuple3 t1 t2 t3
210
+
member_.Run x :'``applicative1<applicative2<applicative3<'t>>>`` = x
211
+
212
+
213
+
181
214
/// Creates a (lazy) monadic computation expression with side-effects (see http://fsprojects.github.io/FSharpPlus/computation-expressions.html for more information)
/// Creates a strict monadic computation expression with side-effects (see http://fsprojects.github.io/FSharpPlus/computation-expressions.html for more information)
0 commit comments