[Haskell-cafe] about Haskell code written to be "too smart"

Gregg Reynolds dev at mobileink.com
Tue Mar 24 17:22:47 EDT 2009

On Tue, Mar 24, 2009 at 1:42 PM, Manlio Perillo
<manlio_perillo at libero.it> wrote:
> But, as an example, when you read a function like:
> buildPartitions xs ns = zipWith take ns . init $ scanl (flip drop) xs ns
> that can be rewritten (argument reversed) as:
> takeList :: [Int] -> [a] -> [[a]]
> takeList [] _         =  []
> takeList _ []         =  []
> takeList (n : ns) xs  =  head : takeList ns tail
>    where (head, tail) = splitAt n xs
> I think that there is a problem.

This crops up all the time even in simple mathematics.  One way to
provide assistance to newcomers is to provide a quasi-English reading
of the notation.  Take as an example a simple set comprehension
expression (using Z email notation,

   { x : Int | 0 < x < 10 /\ x %e Odd @ 2*x }

That's pretty opaque for beginners until they learn to read | as "such
that", %e as "member of" and @ as "generate", so that they can express
the idea in quasi-English:  "form a set by taking  all integers x such
that ... and ..., then generate the result by doubling them" or the
like.  Or take | as "filter" and @ as "map"; the point is it helps to
be able to express it in something like natural language.

Do something similar for your buildPartitions definition and I'll bet
you'll end up with something much more user friendly than takeList.


More information about the Haskell-Cafe mailing list