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

Tom Murphy amindfv at gmail.com
Thu Jul 5 14:23:32 CEST 2012


In practice, the amount of time you have to spend testing each function, to
make sure its IO doesn't trip up in some corner case, is usually greater
than the amount of time a rewrite-for-IO would take.

Tom
On Jun 28, 2012 2:54 PM, "Dominique Devriese" <
dominique.devriese at cs.kuleuven.be> wrote:

> 2012/6/27 Tillmann Rendel <rendel at informatik.uni-marburg.de>:
> > MightyByte wrote:
> >>
> >> Of course every line of your program that uses a Foo will change if you
> >> switch
> >> to IO Foo instead.
> >
> >
> > But we often have to also change lines that don't use Foo at all. For
> > example, here is the type of binary trees of integers:
> >
> >  data Tree = Leaf Integer | Branch (Tree Integer) (Tree Integer)
> >
> > A function to add up all integers in a tree:
> >
> >  amount:: Tree -> Integer
> >  amount (Leaf x) = x
> >  amount (Branch t1 t2) = amountt1 + amountt2
> >
> > All fine so far. Now, consider the following additional requirement: "If
> the
> > command-line flag --multiply is set, the function amount computes the
> > product instead of the sum."
> >
> > In a language with implicit side effects, it is easy to implement this.
> We
> > just change the third line of the amount function to check whether to
> call
> > (+) or (*). In particular, we would not touch the other two lines.
> >
> > 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...
>
> Dominique
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120705/3068cd82/attachment.htm>


More information about the Haskell-Cafe mailing list