Re: [Haskell] How to define tail function for Even/Odd GADT lists?
2008/4/23 Martijn Schrage <martijn@cs.uu.nl>:
It depends a bit on what you want to use these lists for, but the following encoding works for your examples and doesn't need the type class.
data E data O
type Even = (E,O) type Odd = (O,E)
That's a nice little trick! I like how you achieve type signatures relating two distinct types just by sticking them in a tuple. :) David
Hello, I am not sure of the use case here but you could also do the following: data EvenList a = Nil | ConsE a (OddList a) data OddList a = ConsO a (EvenList a) This does not use any type system extensions. -Iavor On Wed, Apr 23, 2008 at 4:46 PM, David Roundy <daveroundy@gmail.com> wrote:
2008/4/23 Martijn Schrage <martijn@cs.uu.nl>:
It depends a bit on what you want to use these lists for, but the following encoding works for your examples and doesn't need the type class.
data E data O
type Even = (E,O) type Odd = (O,E)
That's a nice little trick! I like how you achieve type signatures relating two distinct types just by sticking them in a tuple. :)
David _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
I presume the point was to allow the writing of functions that accept either list type, such as sort :: List a evenorodd -> List a evenorodd or similar. David On Wed, Apr 23, 2008 at 7:55 PM, Iavor DiIatchki <iavor.diatchki@gmail.com> wrote:
Hello, I am not sure of the use case here but you could also do the following:
data EvenList a = Nil | ConsE a (OddList a)
data OddList a = ConsO a (EvenList a)
This does not use any type system extensions.
-Iavor
On Wed, Apr 23, 2008 at 4:46 PM, David Roundy <daveroundy@gmail.com> wrote:
2008/4/23 Martijn Schrage <martijn@cs.uu.nl>:
It depends a bit on what you want to use these lists for, but the following encoding works for your examples and doesn't need the type class.
data E data O
type Even = (E,O) type Odd = (O,E)
That's a nice little trick! I like how you achieve type signatures relating two distinct types just by sticking them in a tuple. :)
David _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
On Wed, 23 Apr 2008, Iavor Diatchki wrote:
Hello, I am not sure of the use case here but you could also do the following:
data EvenList a = Nil | ConsE a (OddList a)
data OddList a = ConsO a (EvenList a)
Or just use: http://darcs.haskell.org/event-list/src/Data/AlternatingList/List/
participants (3)
-
David Roundy -
Henning Thielemann -
Iavor Diatchki