[Haskell-cafe] Re: evaluation semantics of bind

Gregg Reynolds dev at mobileink.com
Thu Feb 5 11:18:38 EST 2009


On Thu, Feb 5, 2009 at 9:53 AM, Gleb Alexeyev <gleb.alexeev at gmail.com>wrote:

> Let's imagine that IO datatype is defined thus:
>
> >{-# LANGUAGE GADTs #-}
> >{-# LANGUAGE NoImplicitPrelude #-}
>
> >import Prelude(Monad, Char)
> >data IO a where
> >    GetChar :: IO Char
> >    Bind :: IO a -> (a -> IO b) -> IO b
>
> >getChar = GetChar
> >(>>=) = Bind
>
> It is perfectly possible to construct IO actions as values of this data
> type and execute them by some function evalIO :: IO -> Prelude.IO with the
> obvious definition. Now the question arises: do you think
> getChar >>= \x -> getChar would be optimized to getChar by compiler?
>

I must be misunderstanding something.  I don't know if it would be optimized
out, but I see no reason why it couldn't be.  There's no data dependency,
right?

-g
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090205/64031749/attachment.htm


More information about the Haskell-Cafe mailing list