[Haskell-beginners] a problem with maps

Ertugrul Soeylemez es at ertes.de
Sat Jul 23 23:46:51 CEST 2011


David Place <d at vidplace.com> wrote:

> >   fromAmbList :: Ord k => [(k, a)] -> Map k [a]
> >    fromAmbList = M.fromListWith (++) . map (second pure)
>
> If I am reading your code, I may look up second and find it in
> Control.Arrow.  I have to learn about Arrows to understand your code?
> And pure makes me need to study the Applicative class.  I imagine that
> it is likely that second is the only thing from Control.Arrow that you
> are using and pure is the only thing from Control.Applicative.  So,
> you need two lines of extra code to express what could be expressed
> much more perspicuously as:

Point taken, but to get serious with Haskell you will want to learn
applicative functors and at least the function arrow anyway.  This is
the solution I would have written, and which would be most readable to
me, and there is a practical reason for that:  I have trained myself to
write my code as composable as possible, hence such code is very easy to
read for me, and I don't really think about it when writing.

Similar comparison:  Why would you want to learn a sophisticated
language like Haskell with a steep learning curve together with the
hassle of setting up a compilation environment on both the development
and production systems and a specialized web server configuration, if
you could just use PHP, which is preinstalled almost everywhere anyway?

Why would you want to use a complicated mechanism like exceptions, if
you could just as well just return an error value?


Greets,
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/





More information about the Beginners mailing list