Re: [Haskell-cafe] Tuple

2011-04-11 Thread Henning Thielemann
Anwar Bari schrieb: I have to make a function to check that I have one occurrence of the last element (z) of the same list [a,b] in the tuple How about using Data.Map? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] Tuple

2011-04-11 Thread Richard O'Keefe
On 11/04/2011, at 4:49 AM, Anwar Bari wrote: HI Cafe I have to make a function to check that I have one occurrence of the last element (z) of the same list [a,b] in the tuple [([a,b],z)] For example [([1,2],3),([1,1],5),([1,3],6)...] this is true because there is one

[Haskell-cafe] Tuple

2011-04-10 Thread Anwar Bari
HI Cafe I have to make a function to check that I have one occurrence of the last element (z) of the same list [a,b] in the tuple [([a,b],z)] For example [([1,2],3),([1,1],5),([1,3],6)...] this is true because there is one single z for each single list. while this one is false

Re: [Haskell-cafe] Tuple

2011-04-10 Thread Rob Nikander
On Sun, Apr 10, 2011 at 12:49 PM, Anwar Bari noor2...@yahoo.com wrote: HI Cafe     I have to make a function to check that I have one occurrence of the last element (z) of the same list [a,b] in the tuple  [([a,b],z)] For example [([1,2],3),([1,1],5),([1,3],6)...]  this is true because

Re: [Haskell-cafe] Tuple

2011-04-10 Thread Henk-Jan van Tuyl
On Sun, 10 Apr 2011 18:49:59 +0200, Anwar Bari noor2...@yahoo.com wrote: HI Cafe I have to make a function to check that I have one occurrence of the last element (z) of the same list [a,b] in the tuple [([a,b],z)] For example [([1,2],3),([1,1],5),([1,3],6)...] this is true

Re: [Haskell-cafe] tuple and HList

2005-03-22 Thread Keean Schupke
Oleg has just pointed out that the 'Show' constraint bellow does not work if you try and use a function from the show class (say 'show'), as the function: test2 l = show l has the type: test2 :: forall a. (Show a) = a - String The technique below works to constrain for membership of a class, So

Re: [Haskell-cafe] tuple and HList

2005-03-21 Thread Keean Schupke
David Menendez wrote: instance Functor ((,) a) where fmap f (x,y) = (x, f y) If we get rid of '(,)' and redefine '(a,b)' as sugar for 'TCons a (TCons b HNil)' (or whatever), then there is no way to declare the above instance. I don't think that's a

Re: [Haskell-cafe] tuple and HList

2005-03-21 Thread Frederik Eaton
You need to swap the arguments to TCons... data TCons l a = TCons !l a Then: instance Functor (TCons (TCons HNil a)) where fmap f (TCons (TCons HNil x) y) = TCons (TCons HNil (f x)) y) How does one solve this problem in general, i.e. when the arguments to a type are in the wrong

Re: [Haskell-cafe] tuple and HList

2005-03-21 Thread David Menendez
Frederik Eaton writes: You need to swap the arguments to TCons... data TCons l a = TCons !l a Then: instance Functor (TCons (TCons HNil a)) where fmap f (TCons (TCons HNil x) y) = TCons (TCons HNil (f x)) y) How does one solve this problem in general, i.e. when the

Re: [Haskell-cafe] tuple and HList

2005-03-20 Thread John Meacham
This was brought up in passing in a recent conversation on haskell-cafe http://www.haskell.org//pipermail/haskell-cafe/2005-March/009321.html It certainly seems like an interesting idea, Would type inference still work okay? The other problem mentioned is that they are not quite isomorphic,

Re: [Haskell-cafe] tuple and HList

2005-03-20 Thread David Menendez
John Meacham writes: This was brought up in passing in a recent conversation on haskell-cafe http://www.haskell.org//pipermail/haskell-cafe/2005-March/009321.html It certainly seems like an interesting idea, Would type inference still work okay? The other problem mentioned is that

Re: [Haskell-cafe] tuple and HList

2005-03-20 Thread Frederik Eaton
This was brought up in passing in a recent conversation on haskell-cafe Sorry, mairix was malfunctioning... It certainly seems like an interesting idea, Would type inference still work okay? I don't understand all of the issues. One is that in the HList paper, rather than constructing

Re: [Haskell-cafe] tuple and HList

2005-03-20 Thread Keean Schupke
Frederik Eaton wrote: Another thing which I don't think is mentioned in the paper, which is convenient, is that you can define HLists all of whose elements are members of a given class: class HListShow l instance HListShow HNil instance (Show a, HListShow l) = HListShow (a :* l) You can avoid

Re: [Haskell-cafe] tuple and HList

2005-03-20 Thread Frederik Eaton
That's a neat technique. Since it's so general it would be nice if there were a way to make it more automatic, could one use template haskell? It seems one should be able to write HListConstraint $(mkConstraint Show) l to generate the declarations automatically. Frederik On Sun, Mar 20, 2005

Re: [Haskell-cafe] tuple and HList

2005-03-20 Thread Keean Schupke
Frederik Eaton wrote: That's a neat technique. Since it's so general it would be nice if there were a way to make it more automatic, could one use template haskell? It seems one should be able to write HListConstraint $(mkConstraint Show) l to generate the declarations automatically. Frederik

Re: [Haskell-cafe] tuple and HList

2005-03-20 Thread David Menendez
Frederik Eaton writes: One way t make tuples into sugar for HLists would be to effectively have a series of declarations like these: type (a,b) = TCons a (TCons b HNil) type (a,b,c) = TCons a (TCons b (TCons c HNil)) But then we can't use tuples in instance declarations.

[Haskell-cafe] tuple and HList

2005-03-19 Thread Frederik Eaton
HList seems just like a tuple, but more powerful because one can access the type structure directly, and more cumbersome because one has to use lengthier constructors a 'nil' terminator. So why not just make tuples synonyms for HLists, so one can use HLists with the shorter notation, and have the