Last active
May 17, 2017 03:29
-
-
Save jayrbolton/6312f4ef06d364e969074f54d76891c4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
interface Functor (F) { | |
map: (a => b) => F(a) => F(b) | |
} | |
interface Applicative(M) > Monad (M) { | |
andThen: M(a) => (a => M(b)) => M(b) | |
} | |
type Maybe (a) { | |
data Nothing | |
data Just(a) | |
implements Functor { | |
map: match { | |
(fn, Nothing()) => Nothing | |
(fn, Just(x)) => Just(fn(x)) | |
} | |
} | |
implements Monad { | |
andThen: match { | |
(Just(x), k) => k(x) | |
(Nothing(), x) => Nothing() | |
} | |
} | |
} | |
const j = Just(1).map(add1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment