[Haskell-cafe] Is there a nicer way to do this?

Ketil Malde ketil at malde.org
Mon Jul 7 02:38:17 EDT 2008


Don Stewart <dons at galois.com> writes:

>>>  splitAt n xs =  (take n xs, drop n xs)

>> Thanks.  That is odd, though.  It makes me wonder what to expect re 
>> optimization.  Would the compiler/runtime know that splitAt could be 
>> done in a single pass?

> Not with that definition. It would require some moderately unusual fusion
> combining the take and drop into a single fold with the (,) on the inside,
> rather than on the outside.

Uhm, but I'm quite sure I saw a paper about how the garbage collector
could discover this, and update both thunks simultaneously.
(Unfortunately, I can't seem to find it now.)

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants


More information about the Haskell-Cafe mailing list