[Haskell-beginners] [Haskell-cafe] select :: [(Float,
a)] -> a -- Weighted stochastic selection - help?
nicolas.pouillard at gmail.com
Sat Sep 6 11:21:30 EDT 2008
Excerpts from C.M.Brown's message of Sat Sep 06 16:43:23 +0200 2008:
> > OK, let's restrict the word side-effect to printing on the screen as the only
> > side-effect possible.
> > Some recalls:
> > Example:
> > putStrLn is a side-effecting function expecting *2* arguments,
> > the first one is the string to print, and the second one is the world state.
> > So if you could give to arguments to putStrLn you could make a side-effect,
> > however you don't have a value of type RealWorld.
> > Is this clear?
> Yes! Thanks for giving such a clear and insightful explanation. I guess I
> forgot about the IO being an abstraction for something else. So can I
> clarify that it's the runtime system that triggers the side-effect, and
> not Haskell?
> I have one last question that is still confusing me: what if I have a
> function that reads something from a file, say, and does
> something depending on that input - would that be a side-effect?
Reading is treated like writing, but it's a little more complicated to
understand because it rely on binding part of (>>=), the first one was
sequencing (as in (>>)).
Example with getLine
getLine >>= \name -> putStrLn ("Hello " ++ name ++ "!")
getLine have type IO String, so it's a function that waits for *1* argument.
(>>=) in the case of IO is a function that expect *3* arguments: the first
is computation that produce something, the second is a function that tell
what to do with the result (a kind of continuation), and the third argument
is again the RealWorld value.
> Consider something modifying a file outside of the Haskell world that
> changes a program's behaviour. Am I right in thinking that the side-effect
> happens at runtime - but in Haskell, the funtion is still pure.
> I feel, also, that as a reasonably experienced Haskell user, I am getting
> confused with what should be fundamental Haskell concepts. Perhaps these
> concepts should be made much clearer to beginners in the first instance.
This article  seems a good introduction. Maybe one could sum-up what you
think is missing from this article and extend it a bit.
For instance one could explain the point about the run-time system.
Nicolas Pouillard aka Ertai
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 194 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/beginners/attachments/20080906/e01ef77e/signature.bin
More information about the Beginners