[Haskell-cafe] about Haskell code written to be "too smart"
manlio_perillo at libero.it
Tue Mar 24 16:51:55 EDT 2009
Jake McArthur ha scritto:
> | With my function, instead, you only have to "follow" 1 operation:
> | Prelude> (head, tail) = splitAt n xs
> I think you are way oversimplifying your own code.
> ~ takeList :: [Int] -> [a] -> [[a]]
> ~ takeList  _ = 
> ~ takeList _  = 
> ~ takeList (n : ns) xs = head : takeList ns tail
> ~ where (head, tail) = splitAt n xs
> In order to understand this, I have to look at three different cases, an
> uncons, a splitAt, a cons, *and* a recursive call. This is *seven*
> different things I have to absorb.
These cases are, IMHO, more "natural".
We have a set of equations, pattern matching and recursion.
These are one of the basic building block of Haskell.
The only "foreign" building block is the splitAt function.
But this may be really a question of personal taste or experience.
What is more "natural"?
1) pattern matching
1) function composition
2) high level functions
More information about the Haskell-Cafe