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

Jake McArthur jake at pikewerks.com
Tue Mar 24 16:32:19 EDT 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Manlio Perillo wrote:
| 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

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.

- - Jake
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAknJQ1MACgkQye5hVyvIUKl+hQCfc7Yd8mi8uXDRTZQa11Pn8zeT
cZMAnApAcI+pr0wpYUP6Z0jHQ2vtf0ze
=Z5ze
-----END PGP SIGNATURE-----


More information about the Haskell-Cafe mailing list