Created
November 5, 2017 13:52
-
-
Save deque-blog/c0fb76fe69a91596715f3b08e08aaa1a to your computer and use it in GitHub Desktop.
This file contains 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
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