[Haskell-cafe] Identity of indiscernibles

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Thu Aug 8 18:05:58 CEST 2013

On Thu, Aug 08, 2013 at 03:38:41PM +0200, Jerzy Karczmarczuk wrote:
> >One could simply implement IO as a free monad
> Interesting. I wonder how.

See [1] for an explanation of free monads in general.  For IO in particular,
define a functor

    data IOF a = GetChar (Char -> a) | PutChar Char a | ...

with constructors for all elementary IO operations.  Then take

type IO a = Free IOF a

and define

    getChar :: IO Char
    getChar = liftF (GetChar id)        
    putChar :: Char -> IO ()
    putChar c = liftF (PutChar c ())

etc..  I make no claims about the performance of a runtime system based on
suhc a representation!


More information about the Haskell-Cafe mailing list