[Haskell-beginners] [Haskell-cafe] select :: [(Float, a)] -> a
-- Weighted stochastic selection - help?
C.M.Brown
cmb21 at kent.ac.uk
Sat Sep 6 10:43:23 EDT 2008
Nicolas,
> 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?
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.
Thanks!
Chris.
More information about the Beginners
mailing list