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

damodar kulkarni kdamodar2000 at gmail.com
Fri Jun 29 05:07:15 CEST 2012


Any idea whether Martin Odersky has read this discussion?

Thanks and regards,
-Damodar Kulkarni


On Fri, Jun 29, 2012 at 12:23 AM, 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/20120629/bcb24147/attachment.htm>


More information about the Haskell-Cafe mailing list