[Haskell-cafe] Martin Odersky on "What's wrong with Monads"

Alvaro Gutierrez radical at google.com
Tue Jul 3 23:49:48 CEST 2012

On Thu, Jun 28, 2012 at 2:53 PM, Dominique Devriese
<dominique.devriese at cs.kuleuven.be> wrote:
> 2012/6/27 Tillmann Rendel <rendel at informatik.uni-marburg.de>:
>> How would you implement this requirement in Haskell without changing the
>> line "amount (Leaf x) = x"?
> I may be missing the point here, but having worked on large code bases
> with a wide variety contributors before, I find it very advantageous
> that programmers are prevented from writing an amount function whose
> behaviour depends on command line arguments without at least an
> indication in the type. The fact that the function can not perform
> stuff like that is precisely the guarantee that the Haskell type gives
> me...

I don't think there's an answer that's uniformly right; it depends on
whether you think of the input to the program, e.g. the environment,
command-line arguments, etc. as 'constant' and in some sense, pure.
The latter are constant in the sense that they never change, but they
are not fixed at compile-time. Other languages effectively treat them
as pure (by passing them directly to main), whereas Haskell chooses
not to, which is probably the reason why getArgs has IO in its type
(something that seems unintuitive at first.)

That precedent supports the view that e.g. a command-line flag
shouldn't affect behavior without the type reflecting it, e.g. by
doing IO, but the de facto use of the unsafe IO trick means not
everyone agrees.

More information about the Haskell-Cafe mailing list