Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Created November 5, 2017 13:52
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 deque-blog/c0fb76fe69a91596715f3b08e08aaa1a to your computer and use it in GitHub Desktop.
Save deque-blog/c0fb76fe69a91596715f3b08e08aaa1a to your computer and use it in GitHub Desktop.
implementation Functor IOSpec where
map f = assert_total recur where
recur (Pure a) = Pure (f a)
recur (ReadLine cont) = ReadLine (recur . cont)
recur (WriteLine s next) = WriteLine s (recur next)
implementation Applicative IOSpec where
pure = Pure
(<*>) pf a = assert_total (recur pf) where
recur (Pure f) = map f a
recur (ReadLine cont) = ReadLine (recur . cont)
recur (WriteLine s next) = WriteLine s (recur next)
implementation Monad IOSpec where
(>>=) ma f = assert_total (recur ma) where
recur (Pure a) = f a
recur (ReadLine cont) = ReadLine (recur . cont)
recur (WriteLine s next) = WriteLine s (recur next)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment