What about tuple accessor function for (,,) ... ?
Neil Mitchell
ndmitchell at gmail.com
Wed Apr 25 10:18:22 EDT 2007
Hi Marc,
> What about
> fstOf3 ( \(x,_,_) -> x )
> sndOf3 ( \(_,x,_) -> x )
> thrdOf3 ( \(_,_,x) -> x )
I have defined "fst3", "snd3", "thd3". I would strongly support adding
them to the standard libraries, in Data.Tuple.
> class Second a b | a -> b where
> t2 :: a -> b
> instance Second (a,b) b where t2 (a,b) = b
> instance Second (a,b,c) b where t2 (a,b,c) = b
> instance Second (a,b,c,d) b where t2 (a,b,c,d) = b
> instance Second (a,b,c,d,e) b where t2 (a,b,c,d,e) = b
I do not think we should encourage this, if people want to do these
kind of tuple tricks, the solution is one of:
1) make tuples inductive (a,(b,c)), then thd = snd . snd
2) use HList (i think this would give you want you need)
3) use records
The Yhc compiler uses 8 element tuples in some places - its not a good
solution ever.
I suspect the use of the 2 element tuple is really common, the 3
element tuple sees a few outings, and the 4 and above element tuple is
a bit of a rarity.
Following the proposal tradition, there about about 100 hits for each
of fst3 etc on Google Code Search. They occur in HaXml, Cabal, Gofer,
Hat, Chameleon, Hoogle, nhc, Yhc etc.
Thanks
Neil
More information about the Libraries
mailing list