Skip to content

Instantly share code, notes, and snippets.

@michelrandahl
Created March 12, 2017 02:33
Show Gist options
  • Save michelrandahl/b512686a6685a47efc7801bbcb5328e9 to your computer and use it in GitHub Desktop.
Save michelrandahl/b512686a6685a47efc7801bbcb5328e9 to your computer and use it in GitHub Desktop.
-- Attempting to implement my own Maybe monad using the Option type naming from F#
data Option x = None
| Some x
Functor Option where
map f None = None
map f (Some x) = Some (f x)
Applicative Option where
pure x = Some x
(<*>) (Some f) (Some x) = Some (f x)
(<*>) _ _ = None
Monad Option where
(>>=) None _ = None
(>>=) (Some x) f = f x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment