[Haskell-cafe] tuples and Show in GHC

Keean Schupke k.schupke at imperial.ac.uk
Mon Mar 7 10:54:07 EST 2005


Remi Turk wrote:

>On Mon, Mar 07, 2005 at 12:05:41AM +0000, Keean Schupke wrote:
>  
>
>>Daniel Fischer wrote:
>>
>>    
>>
>>>The Show instances for tuples aren't automatically derived, they are 
>>>defined in GHC.Show. So somewhere there must be an end, probably the 
>>>author(s) thought that larger tuples than quintuples aren't used often 
>>>enough to bother. That's not a principled reason but a practical one, but 
>>>it's good enough for me.
>>>If you need them frequently and don't want to define your own instances, 
>>>complain.
>>>BTW, tuples are defined in Data.Tuple up to 62-tuples and Eq and Ord 
>>>instances are derived up to 15-tuples.
>>>In Hugs, apparently they are only provided up to quintuples.
>>>
>>>      
>>>
>>Has there been any work done on declaring instances over all tuples? It 
>>seems the pattern occurs fairly often, and is quite simple to abstract.
>>
>>   Keean.
>>    
>>
>
>Which almost sounds like a hint to replace the current tuples by
>HLists in Haskell 2? ;)
>
>Something like:
>
>infixr 5 :*:
>data HNil = HNil
>data HList b => a :*: b = a :*: !b deriving (Eq, Ord)
>
>-- type () = HNil
>type (a,b) = a :*: b :*: HNil
>type (a,b,c) = a :*: b :*: c :*: HNil
>
>fst :: HList b => (a :*: b) -> a
>fst (a:*:b) = a
>
>Where (x,y,z) is syntactic sugar for x :*: y :*: z :*: HNil in
>much the same way [x,y,z] is syntactic sugar for x:y:z:[]...
>
>It might even be (almost?) backward compatible AFAICS.
>
>Groeten,
>Remi
>  
>
Whilst thats certainly one way to do it, HLists are composed of binary 
products (,)...  So this
works as long as you can imagine: (a,(b,(c,HNil))) == (a,b,c)

We can define the operations generically using HLists, and we can even 
convert back and
forth from a tuple to an HList (for a limited number of tuple instances).
Infact we might be able to do conversion of arbitrary tuples using 
template-haskell.

    Keean.


More information about the Haskell-Cafe mailing list