[Haskell-cafe] about Haskell code written to be "too smart"
Peter Verswyvelen
bugfact at gmail.com
Tue Mar 24 16:38:16 EDT 2009
On Tue, Mar 24, 2009 at 7:48 PM, Jonathan Cast <jonathanccast at fastmail.fm>wrote:
> On Tue, 2009-03-24 at 19:42 +0100, Manlio Perillo 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
>
> Huh? This is ugly and un-readable. Seriously.
>
I think this is subjective. Personally I can understand the second
definition immediately, but the first one requires some puzzling. But that
might be because I'm relatively new to Haskell. Of course the usage of head
and tail in the example is unfortunate, one should not use these shadowing
names.
But aren't these two definitions different algoritms? At first sight I think
the second one is more efficient than the first one.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090324/fcd08e6d/attachment.htm
More information about the Haskell-Cafe
mailing list