IO does not do side-effects. Start here.
| {-# LANGUAGE NoImplicitPrelude #-} | |
| import Control.Monad.Free | |
| import Prelude(Functor(..), Monad(..), (.), Char) | |
| data IO'Op a = | |
| PutChar Char a | |
| | GetChar (Char -> a) | |
| instance Functor IO'Op where | |
| fmap f (PutChar c a) = | |
| PutChar c (f a) | |
| fmap f (GetChar k) = | |
| GetChar (f . k) | |
| type IO' a = | |
| Free IO'Op a | |
| putChar :: | |
| Char | |
| -> IO' () | |
| putChar c = | |
| Free (PutChar c (return ())) | |
| getChar :: | |
| IO' Char | |
| getChar = | |
| Free (GetChar return) | |
| program = | |
| do | |
| c1 <- getChar | |
| c2 <- getChar | |
| putChar c1 | |
| putChar c2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment