diff --git a/docsrc/content/type-reader.fsx b/docsrc/content/type-reader.fsx index 5e516eba3..cc01166e7 100644 --- a/docsrc/content/type-reader.fsx +++ b/docsrc/content/type-reader.fsx @@ -106,7 +106,7 @@ let lookupTemplate (name:string) (env:Environment) : Template option = tryItem n /// add a list of resolved definitions to the environment let addDefs (defs:(string*string) list) env = { env with variables = plus (Map.ofList defs) env.variables} - +#if APPLICATIVE_FIX /// resolve a template into a string let rec resolve : Template -> Reader = function | T s -> result s @@ -150,4 +150,6 @@ Recommended reading - Highly recommended Matt Thornton's blog [Grokking the Reader Monad](https://dev.to/choc13/grokking-the-reader-monad-4f45). It contains examples using F#+ and an explanation from scratch. -*) \ No newline at end of file +*) + +#endif \ No newline at end of file diff --git a/src/FSharpPlus.Docs/FSharpPlus.Docs.fsproj b/src/FSharpPlus.Docs/FSharpPlus.Docs.fsproj index f25f1af8f..f5aefdaee 100644 --- a/src/FSharpPlus.Docs/FSharpPlus.Docs.fsproj +++ b/src/FSharpPlus.Docs/FSharpPlus.Docs.fsproj @@ -9,6 +9,7 @@ Debug;Release;Fable AnyCPU net7.0 + $(DefineConstants);APPLICATIVE_FIX diff --git a/src/FSharpPlus.Docs/Samples/Learn You a Haskell.fsx b/src/FSharpPlus.Docs/Samples/Learn You a Haskell.fsx index a9f043aef..915eefa9d 100644 --- a/src/FSharpPlus.Docs/Samples/Learn You a Haskell.fsx +++ b/src/FSharpPlus.Docs/Samples/Learn You a Haskell.fsx @@ -258,7 +258,7 @@ let res70 = applyLog (3, "Smallish gang.") isBigGang // let res71: Writer, unit> = tell ["Something gonna happend"] // Writer (None, ["Something gonna happend"]) let logNumber (x:int) = Writer (x, ["Got number: " + (x |> string)]) - +#if APPLICATIVE_FIX let multWithLog = // Writer (15, ["Got number: 3"; "Got number: 5"; "Gonna multiply these two"]) monad { let! a = logNumber 3 @@ -285,7 +285,7 @@ let rec gcd' a b : Writer, int> = } let res72 = gcd' 8 3 // Writer (1, ["8 mod 3 = 2"; "3 mod 2 = 1"; "2 mod 1 = 0"; "Finished with 1"]) - +#endif (* -------------------------------------------------- Reader monad @@ -421,6 +421,8 @@ let inline filterM (f : 'a -> 'Monad'Bool) (xs : List<'a>) : 'Monad'List'a = } loopM f xs +#if APPLICATIVE_FIX + // keepSmall :: Int -> Writer [String] Bool let keepSmall x : Writer, bool> = monad { @@ -441,6 +443,7 @@ let res96 = keepSmall 3 let res97 = filterM keepSmall [9;1;5;2;10;3] // Writer ([1; 2; 3], ["9 is too large, throwing it away"; "Keeping 1"; "5 is too large, throwing it away"; "Keeping 2"; "10 is too large, throwing it away"; "Keeping 3"]) let res98 = filterM keepSmallSome [1;2;3] // Some [1; 2; 3] let res99 = filterM keepSmallSome [9;1;5;2;10;3] // None +#endif // foldM :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m a // foldM _ a [] = return a diff --git a/src/FSharpPlus/Builders.fs b/src/FSharpPlus/Builders.fs index 0936ae1df..e9e7a56cb 100644 --- a/src/FSharpPlus/Builders.fs +++ b/src/FSharpPlus/Builders.fs @@ -47,6 +47,7 @@ module GenericBuilders = member inline _.Bind (p: '``Monad<'T>``, []rest: 'T->'``Monad<'U>``) = p >>= rest : '``Monad<'U>`` member inline _.MergeSources (t1: '``Monad<'T>``, t2: '``Monad<'U>``) : '``Monad<'T * 'U>`` = Lift2.Invoke tuple2 t1 t2 member inline _.MergeSources3 (t1: '``Monad<'T>``, t2: '``Monad<'U>``, t3: '``Monad<'V>``) : '``Monad<'T * 'U * 'V>`` = Lift3.Invoke tuple3 t1 t2 t3 + member inline _.BindReturn (x : '``Monad<'T>``, f: 'T -> 'U) : '``Monad<'U>`` = Map.Invoke f x [] member inline _.Select (x, [] f) = map f x diff --git a/tests/FSharpPlus.Tests/FSharpPlus.Tests.fsproj b/tests/FSharpPlus.Tests/FSharpPlus.Tests.fsproj index 4e1743d02..7adaeb902 100644 --- a/tests/FSharpPlus.Tests/FSharpPlus.Tests.fsproj +++ b/tests/FSharpPlus.Tests/FSharpPlus.Tests.fsproj @@ -10,8 +10,8 @@ false Debug;Release;Fable;Test AnyCPU - $(DefineConstants);TEST_TRACE - $(DefineConstants);FABLE_COMPILER + $(DefineConstants);TEST_TRACE;APPLICATIVE_FIX + $(DefineConstants);FABLE_COMPILER;APPLICATIVE_FIX net7.0 diff --git a/tests/FSharpPlus.Tests/General.fs b/tests/FSharpPlus.Tests/General.fs index f6f9b0a3e..d9fc20033 100644 --- a/tests/FSharpPlus.Tests/General.fs +++ b/tests/FSharpPlus.Tests/General.fs @@ -1454,7 +1454,7 @@ module MonadTransformers = let _ = put initialState : ChoiceT>> () - +#if APPLICATIVE_FIX [] let testStateT () = let lst1: StateT = StateT.lift [1;2] @@ -1489,6 +1489,7 @@ module MonadTransformers = areEqual (Ok 11) x let y = (fn |> ResultT.run |> Reader.run) -1 areEqual (Error NegativeValue) y +#endif module ProfunctorDefaults = type Fun<'T,'U> = Fun of ('T -> 'U) with diff --git a/tests/FSharpPlusFable.Tests/FSharpTests/General.fs b/tests/FSharpPlusFable.Tests/FSharpTests/General.fs index c23fc6b14..92e0d06ba 100644 --- a/tests/FSharpPlusFable.Tests/FSharpTests/General.fs +++ b/tests/FSharpPlusFable.Tests/FSharpTests/General.fs @@ -122,7 +122,7 @@ let monadTransformers = testList "MonadTransformers" [ let _ = put initialState : ChoiceT>> ()) - #if !NETSTANDARD3_0 + #if APPLICATIVE_FIX testCase "testStateT" (fun () -> let lst1: StateT = StateT.lift [1;2] let lst2: StateT = StateT.lift [4;5]