[Haskell-cafe] Thinking about an unlistN

Michael Feathers mfeathers at mindspring.com
Sun Aug 10 14:57:25 EDT 2008



Philip,

Thanks.  It's not quite that, though.  It's more like an adapter for a 
function with a specific arity.

If I have, say, a function f :: a -> a -> a -> a -> b it would be nice 
to be able to just:

unlistN 4 f [1..4]


Michael (does look like there's no way to make that fly with the type 
system however)



Philip Neustrom wrote:
> I'm no expert, but it looks like the generalization of that would be
> some f that took a list:
> 
> f :: [a] -> b
> 
> so what you'd have is a fold, right?
> 
> foldr1 :: (a -> a -> a) -> [a] -> a
> 
> Best,
> Philip Neustrom
> 
> On Sun, Aug 10, 2008 at 11:47 AM, Michael Feathers
> <mfeathers at mindspring.com> 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.
>>
>>
>> Thanks,
>>
>> Michael
>>
>>
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
> 


-- 
Now Playing: Clammbon - 246
http://youtube.com/watch?v=PO77bN8W1mA




More information about the Haskell-Cafe mailing list