[Haskell-beginners] Re: testing and the culture of Haskell

Stephen Blackheath [to Haskell-Beginners] mutilating.cauliflowers.stephen at blacksapphire.com
Thu Jan 21 05:20:34 EST 2010


Isaac,

Isaac Dupree wrote:
> Heinrich Apfelmus wrote:
>> Or more precisely, their type system does not distinguish
>> between functions with and without side effects.
> 
> that's not actually more precise! Haskell doesn't entirely do that
> either. consider:
> f :: Int -> IO Int
> f x = return (x + 1)
> No side effects! But other ->IO typed values do yield side-effects.

All Haskell functions are pure without exception.  For example:

greet :: String -> IO ()
greet name = putStrLn $ "Hello, "++name

This is a pure function from String to IO ().  This function (like all
Haskell functions) has no side effects.  Its return value of type IO ()
merely _represents_ an IO action.  The runtime system knows how to act
on this representation.

This also means that there is no such thing in Haskell as marking a
function as side-effecting.

This distinction may be subtle, but it's important.


Steve



More information about the Beginners mailing list