"Recursion is the goto of functional programming". Also, "Do not confuse what is natural with what is habitual." - Conal
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
2) recursion
or
1) function composition
2) high level functions
?
> [...]
Manlio
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe