[Haskell-cafe] mapTuple
Arthur van Leeuwen
arthurvl at cs.uu.nl
Thu Jan 11 11:32:22 EST 2007
On 11-jan-2007, at 16:30, Marco Túlio Gontijo e Silva wrote:
> Em Qui, 2007-01-11 às 16:14 +0100, minh thu escreveu:
>> you might want invistigate "heterogeneous lists" : in your case, it's
>> "heterogeneous typle".
>
> But aren't tuples always heterogeneous?
Yes, and precisely therein lies the problem. There is no way
for the compiler to infer that in
tupleMap f (a, b) = (f a, f b)
the type of f should be polymorphic. If you want it to be,
explicitly require it to be so:
tupleMap :: (forall a b . a -> b) -> (b,c) -> (d,e)
tupleMap f (a,b) = (f a, f b)
However, this will still not allow you to write
tupleMap show ("string",3)
as you require f to be fully polymorphic, and not constrained by any
context.
With regards, Arthur.
--
/\ / | arthurvl at cs.uu.nl | Work like you don't need
the money
/__\ / | A friend is someone with whom | Love like you have never
been hurt
/ \/__ | you can dare to be yourself | Dance like there's nobody
watching
More information about the Haskell-Cafe
mailing list