File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -316,3 +316,39 @@ module Fold =
316316 |> Identity.run
317317
318318 areStEqual ( Ok { Id = FooId " 1" ; Name = " test" }) response
319+
320+ module Lift3 =
321+
322+ type Instruction < 'next > =
323+ | Read of int * ( string -> 'next )
324+ static member Map ( i , f ) =
325+ match i with
326+ | Read ( x, next) -> Read( x, next >> f)
327+
328+ let read x = Read( x, id) |> Free.liftF
329+
330+ type ApplicativeBuilder < 'a >() =
331+ inherit MonadFxStrictBuilder< 'a>()
332+
333+ member inline _.BindReturn ( x , f ) = map f x
334+
335+ let applicative < 'a > = ApplicativeBuilder< 'a>()
336+
337+ [<Test>]
338+ let ``should be able to use applicative CE which requires Lift3`` () =
339+ let program =
340+ applicative {
341+ let! a = read 1
342+ and! b = read 2
343+ and! c = read 3
344+ return a, b, c
345+ }
346+
347+ let result =
348+ program
349+ |> Free.fold
350+ ( function
351+ | Read ( i, next) -> i |> string |> next |> result)
352+ |> Identity.run
353+
354+ areStEqual result ( " 1" , " 2" , " 3" )
You can’t perform that action at this time.
0 commit comments