[Haskell-beginners] [Haskell-cafe] select :: [(Float, a)] ->
a -- Weighted stochastic selection - help?
apfelmus
apfelmus at quantentunnel.de
Sat Sep 6 10:18:10 EDT 2008
C.M.Brown wrote:
>> Technically, even the IO monad is pure, that's just the runtime-system
>> > that consume your 'main' function that perform effects (and unsafeP...).
>
> But, sure the IO monad does have side-effects? I'm confused as to how it
> could be pure. Could you explain?
> I'm sorry, but I just don't get it. What are you trying to say? I think it
> would be clearer if we started to define what exactly a "side-effect" is
> (in any language) and work our definitions from there, because now I'm
> really confused.
A function say f :: Int -> Int is said to be *pure* if its result depends only
on the argument.
In Haskell, all functions are pure and the IO monad doesn't change anything
about that. This is what is meant by "IO is pure". While IO allows you to print
stuff on the screen, it doesn't change the fundamental property of the language
that all functions are free of side-effects.
In other languages like C or even ML, there are functions like
putStr :: String -> ()
getChar :: () -> Char
whose results depend on more things than their parameter and who can perform
side-effects.
Regards,
apfelmus
More information about the Beginners
mailing list