[Haskell-cafe] Referential Transparency and Monads

Luke Palmer lrpalmer at gmail.com
Thu Apr 9 14:52:01 EDT 2009


2009/4/9 Mark Spezzano <mark.spezzano at chariot.net.au>

> Or does RT ignore the encapsulated data and just view the “action”
> performed by the monad as the “value” of the monad?
>

If I understand you right, this is more-or-less correct.

You may as well think of IO as some sort of algebraic type that you are
building and returning.  A value of type "IO Integer" is not, itself, an
integer.  Thus:

main =
  let r = print "hello"
  in return ()

Prints nothing.  RT steps in in a similar scenario:

main =
  let r = print "hello"
  in do { r; r }

Replacing "r" with its definition:

main = do { print "hello"; print "hello" }

As expected.

Luke



>
> Just curious as to the rationale behind referential transparency and how it
> applies to monads.
>
>
>
> Cheers,
>
>
>
> Mark Spezzano
>
>
>
> No virus found in this outgoing message.
> Checked by AVG.
> Version: 7.5.557 / Virus Database: 270.11.48/2048 - Release Date: 8/04/2009
> 7:02 PM
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090409/39bb8044/attachment.htm


More information about the Haskell-Cafe mailing list