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

Heinrich Apfelmus apfelmus at quantentunnel.de
Fri Jan 22 05:31:53 EST 2010

Isaac Dupree wrote:
> Heinrich Apfelmus wrote:
>> However, in a sense, one can interpret the pure in purely functional as
>> a property of the type constructor (->) , i.e. a function of type  (a ->
>> b)  is guaranteed to not have side effects. In this light, ML and Scheme
>> are lacking a very important type: they only have functions with side
>> effects.
>> 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.
> It is exactly as if ML and Scheme contain only the type of (->) composed
> with IO.  (Well, actually Scheme is dynamically typed so it's a bit
> silly to say so..)  (and Scheme allows functions with zero arguments,
> which are different from its non-side-effecting values.. not sure about ML)

Yes, "distinguish" in the sense of "optional distinction by annotation"
instead of "automatically detect whether a function has side effects or

(By the way, in a sense it is possible to detect that  f  has no side
effects. Namely, it's most general type is polymorphic in the monad:

    f :: Monad m => Int -> m Int

This is much like Java lacking (having lacked?) types whose values
cannot be  null , compared to  a  vs  Maybe a  in Haskell.

Heinrich Apfelmus


More information about the Beginners mailing list