Skip to content

Instantly share code, notes, and snippets.

@Janiczek
Created August 29, 2021 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Janiczek/a979c8a8f59d4a5186b2a340991a3aef to your computer and use it in GitHub Desktop.
Save Janiczek/a979c8a8f59d4a5186b2a340991a3aef to your computer and use it in GitHub Desktop.
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