-
-
Save Janiczek/a979c8a8f59d4a5186b2a340991a3aef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type alias ErrorM e a = | |
Result e a | |
type alias StateM s a = | |
s -> ( a, s ) | |
type alias MyMonad e s a = | |
ErrorM e (StateM s a) | |
andThen : (a -> MyMonad e s b) -> MyMonad e s a -> MyMonad e s b | |
andThen userFn m = | |
case m of | |
Err err -> | |
Err err | |
Ok stateFn -> | |
Ok <| | |
\state -> | |
let | |
( a, stateA ) = | |
stateFn state | |
in | |
userFn a | |
-- this is wrong: | |
-- returns: MyMonad e s (MyMonad e s b) | |
-- instead of: MyMonad e s b | |
-- looks like job for `join : MyMonad e s (MyMonad e s a) -> MyMonad e s a` | |
-- but my brain is crapping out on that one also |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment