[Haskell-cafe] Thinking about an unlistN

Anton van Straaten anton at appsolutions.com
Sun Aug 10 16:42:04 EDT 2008

Michael Feathers wrote:
> I wrote this function the other day, and I was wondering if I'm missing 
> something.. whether there is already a function or idiom around to do this.
> unlist3 :: (a -> a -> a -> b) -> [a] -> b
> unlist3 f (x:y:z:xs) = f x y z
> I was also wondering whether the function can be generalized to N or 
> whether this is just one of those edges in the type system that you 
> can't abstract over.

In Scheme and Lisp, the "apply" function does this, so the following 
Scheme definition would do the trick:

   (define unlist apply)

(Although this doesn't ignore the xs as in the example; that would 
require some code to extract a sublist of the desired length.)

In Haskell, bring on the type system shenanigans!  ;)


More information about the Haskell-Cafe mailing list