Skip to content

Instantly share code, notes, and snippets.

@jayrbolton
Last active May 17, 2017 03:29
Show Gist options
  • Save jayrbolton/6312f4ef06d364e969074f54d76891c4 to your computer and use it in GitHub Desktop.
Save jayrbolton/6312f4ef06d364e969074f54d76891c4 to your computer and use it in GitHub Desktop.
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