Re:Explaining monads

Sorry to spam you Jeff, again I sent my email to the poster rather than the list. I'm using Yahoo beta webmail and don't see a way to set it to reply to the list rather than the originator. Anyway, this was my post:
Hence the need to perform a "run" operation like runIdentity, evalState or runParser (for Parsec) to get something useful to happen. Except for lists we don't seem to do this. I suppose lists are so simple that the operators :, ++ and the [] constructor do all we ever need with them. Finally there is no runIO because "main" is essentially that function in every real program? - Greg
----- Original Message ----
From: Jeff Polakow

On 15/08/07, Gregory Propf
runParser (for Parsec) to get something useful to happen. Except for lists we don't seem to do this. I suppose lists are so simple that the operators :, ++ and the [] constructor do all we ever need with them. Finally there is no runIO because "main" is essentially that function in every real program? - Greg
What the run functions do is unwrap the monad. They take apart the 'm a' and give you back whatever a's might be inside, and whatever extra stuff too. (Also feeding extra stuff in when m is like that) Doing that will involve actually evaluating the value, forcing all the data dependencies and making the 'actions' happen. If the monad type 'm a' is already a type we can take apart directly (list, maybe etc.) theres no need for a run function. Note that of course unsafePerformIO is runIO. Its just that it doesn't really nest safely, so we like to only use the top level one from main. -- Brian_Brunswick____brian@ithil.org____Wit____Disclaimer____!Shortsig_rules!

Hello,
Hence the need to perform a "run" operation like runIdentity, evalState or runParser (for Parsec) to get something useful to happen. Except for lists we don't seem to do this. I suppose lists are so simple that the operators :, ++ and the [] constructor do all we ever need with them. Finally there is no runIO because "main" is essentially that function in every real program? - Greg
For lists, head is probably the simplest "run" operation. As Brian noted earlier unsafePerformIO is a way to "run" IO computations within your code; but doing so breaks the abstraction of IO as being the outside world. -Jeff --- This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
participants (3)
-
Brian Brunswick
-
Gregory Propf
-
Jeff Polakow