Created
March 2, 2013 16:16
-
-
Save arildm/5071749 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
type IP a = State -> (State,a) | |
data State | |
andThen :: IP a -> (a -> IP b) -> IP b | |
f `andThen` g = \s0 -> let (s1,a) = f s0 | |
(s2,b) = g a s1 | |
in (s2,b) | |
instance Monad IP where | |
(>>=) = andThen | |
return x = \s -> (s,x) | |
safePrint line = do | |
noInk <- outOfInk | |
if noInk | |
then return -1 | |
else do print line | |
return 0 | |
outOfInk = \s -> (s,False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
And with
{-# LANGUAGE TypeSynonymInstances #-}
: