[Haskell-cafe] Newbie question about tuples
Jules Bean
jules at jellybean.co.uk
Fri Jul 13 17:50:05 EDT 2007
Andrew Coppin wrote:
> Lukas Mai wrote:
>> Am Donnerstag, 12. Juli 2007 20:14 schrieb Andrew Coppin:
>>
>>
>>> The only thing the libraries provide, as far as I can tell, is the fact
>>> that tuples are all Functors. (In other words, you can apply some
>>> function to all the elements to get a new tuple.) I think that's about
>>> it. I doubt you can use that to define lifting functions...
>>>
>>
>> Actually, they aren't (Functors).
>
> Oh. Kay... well that makes me look *very* intelligent. :-}
>
>> (,) takes two type arguments, (,,)
>> takes three, etc. class Functor f requires f to take one type argument.
>>
>
> Ah. A kind error. Yes, you're right about that... oops.
>
nah, you do yourself an injustice, Andrew.
(a,b) is certainly functorial, in both a, and in b. I.e. (,b) is a
functor "in the a component", and so is (a,) "in the b component".
Furthermore (a,a) is also functorial: it's just "lists of exactly length
two" and we know lists are functorial.
It is a deficiency of the haskell class system (although I'm not trying
to claim it's a particularly important one in practice) that it's not
really possible to express all these things at once.
You can express them via newtypes if you want to, of course. E.g.:
newtype TwoTuple a = (a,a)
instance TwoTuple Functor where fmap f (x,y) = (f x,f y)
Jules
More information about the Haskell-Cafe
mailing list