tuples and Show in GHC

hi all, Is there a principled reason why in GHC tuples with up to five elements automatically derive from the Show class but from six elements and up they don't anymore? If this is not a bug I would be very curious to hear what the reasoning behind this is.... below is an example of said behaviour :
type MyInt1 = (Int,Int,Int,Int,Int) myInt1 :: MyInt1 myInt1 = (1,2,3,4,5) type MyInt2 = (Int,Int,Int,Int,Int,Int) myInt2 :: MyInt2 myInt2 = (1,2,3,4,5,6)
.... *HS> myInt1 Loading package haskell98 ... linking ... done. (1,2,3,4,5) *HS> myInt2 <interactive>:1: No instance for (Show MyInt2) arising from use of `print' at <interactive>:1 In a 'do' expression: print it *HS> stijn.

Am Sonntag, 6. März 2005 10:40 schrieb Stijn De Saeger:
hi all,
Is there a principled reason why in GHC tuples with up to five elements automatically derive from the Show class but from six elements and up they don't anymore? If this is not a bug I would be very curious to hear what the reasoning behind this is....
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. Hope, this isn't too disappointing, Daniel

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.

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 -- Nobody can be exactly like me. Even I have trouble doing it.

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.

On Mon, Mar 07, 2005 at 03:54:07PM +0000, Keean Schupke wrote:
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)
If we make the list constructor :*: strict in its second argument data a :*: b = a :*: !b then they are isomorphic, no? John -- John Meacham - ⑆repetae.net⑆john⑈
participants (5)
-
Daniel Fischer
-
John Meacham
-
Keean Schupke
-
Remi Turk
-
Stijn De Saeger