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

Manlio Perillo manlio_perillo at libero.it
Tue Mar 24 16:04:27 EDT 2009


Jake McArthur ha scritto:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Manlio Perillo wrote:
> | This is right.
> | The problem is that often (IMHO) a function definition can be rewritten
> | so that it is much more readable.
> |
> | As an example, with the takeList function I posted.
> 
> I looked at it, found nothing wrong with the original, and absolutely
> hated your "fixed" version. 

With the original version, you have to "follow" 3 separate operations:

Prelude> let xs = [1, 2, 3, 4] :: [Int]
Prelude> let ns = [3, 1] :: [Int]
Prelude> let _1 = scanl (flip drop) xs ns
Prelude> let _2 = init _1
Prelude> let _3 = zipWith take ns _2


With my function, instead, you only have to "follow" 1 operation:

Prelude> (head, tail) = splitAt n xs

 > [...]


Manlio


More information about the Haskell-Cafe mailing list