Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "-BindReturn" #428

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docsrc/content/type-reader.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Environment,string> = function
| T s -> result s
Expand Down Expand Up @@ -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.

*)
*)

#endif
1 change: 1 addition & 0 deletions src/FSharpPlus.Docs/FSharpPlus.Docs.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<Configurations>Debug;Release;Fable</Configurations>
<Platforms>AnyCPU</Platforms>
<TargetFramework>net7.0</TargetFramework>
<DefineConstants>$(DefineConstants);APPLICATIVE_FIX</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down
7 changes: 5 additions & 2 deletions src/FSharpPlus.Docs/Samples/Learn You a Haskell.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ let res70 = applyLog (3, "Smallish gang.") isBigGang //
let res71: Writer<List<string>, 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
Expand All @@ -285,7 +285,7 @@ let rec gcd' a b : Writer<List<string>, 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
Expand Down Expand Up @@ -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<List<string>, bool> =
monad {
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/FSharpPlus/Builders.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module GenericBuilders =
member inline _.Bind (p: '``Monad<'T>``, [<InlineIfLambda>]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

[<CustomOperation("select", MaintainsVariableSpaceUsingBind=true, AllowIntoPattern=true)>]
member inline _.Select (x, [<ProjectionParameter>] f) = map f x
Expand Down
4 changes: 2 additions & 2 deletions tests/FSharpPlus.Tests/FSharpPlus.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<IsPackable>false</IsPackable>
<Configurations>Debug;Release;Fable;Test</Configurations>
<Platforms>AnyCPU</Platforms>
<DefineConstants Condition=" '$(Configuration)' == 'Test'">$(DefineConstants);TEST_TRACE</DefineConstants>
<DefineConstants Condition=" '$(Configuration)' == 'Fable'">$(DefineConstants);FABLE_COMPILER</DefineConstants>
<DefineConstants Condition=" '$(Configuration)' == 'Test'">$(DefineConstants);TEST_TRACE;APPLICATIVE_FIX</DefineConstants>
<DefineConstants Condition=" '$(Configuration)' == 'Fable'">$(DefineConstants);FABLE_COMPILER;APPLICATIVE_FIX</DefineConstants>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion tests/FSharpPlus.Tests/General.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ module MonadTransformers =
let _ = put initialState : ChoiceT<State<int, Choice<unit,string>>>

()

#if APPLICATIVE_FIX
[<Test>]
let testStateT () =
let lst1: StateT<string,_> = StateT.lift [1;2]
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/FSharpPlusFable.Tests/FSharpTests/General.fs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ let monadTransformers = testList "MonadTransformers" [
let _ = put initialState : ChoiceT<State<int, Choice<unit,string>>>

())
#if !NETSTANDARD3_0
#if APPLICATIVE_FIX
testCase "testStateT" (fun () ->
let lst1: StateT<string,_> = StateT.lift [1;2]
let lst2: StateT<string,_> = StateT.lift [4;5]
Expand Down
Loading