Re: container for different types, avoiding boiler plate

2003-08-21 Thread oleg
You might also wish to look at the typed heaps, which have been discussed here on many occasions. Given the constant piece of code in the appendix (which does *not* depend on user types and can be put into a separate, constant module) you can write > data Gender = Masc | Fem | Neutr deriving (S

RE: overlapping instances and functional dependencies

2003-08-21 Thread Simon Peyton-Jones
| With overlapping instances, I'm allowed | | class OK x y | | instance Functor f => OK (f x) (f y) | | instance Functor f => OK x (f y) | | but I'm not allowed | | class Bad x y z | x y -> z | | instance Functor f => Bad (f x) (f y) Bool | | instance Functor f => Bad x (f y) Int

RE: overlapping instances and functional dependencies

2003-08-21 Thread Simon Peyton-Jones
| class C a b c | a b -> c where | f :: a -> b -> c | | instance C a b c => C a (x,y,b) c where | f a (_,_,b) = f a b | | instance C a (a,c,b) c where | f _ (_,c,_) = c | ghci -fglasgow-exts -fallow-overlapping-instances compiles it without | complaint but hug

Re: overlapping instances and functional dependencies

2003-08-21 Thread Tom Pledger
C T McBride writes: : | but I'm not allowed | | class Bad x y z | x y -> z | | instance Functor f => Bad (f x) (f y) Bool | | instance Functor f => Bad x (f y) Int | | I don't quite see why. Naively, I imagine that if the OK instances are | effectively prioritized, then Bad's r

RE: container for different types, avoiding boiler plate

2003-08-21 Thread Hal Daume
Yes, this is essentially what DynamicMap isThe url i posted before was wrong...it should have been: www.isi.edu/~hdaume/haskell/DynamicMap.hs -- Hal Daume III | [EMAIL PROTECTED] "Arrest this man, he talks in maths." | www.isi.edu/~hdaume > -

Re: overlapping instances and functional dependencies

2003-08-21 Thread C T McBride
Hi all With overlapping instances, I'm allowed class OK x y instance Functor f => OK (f x) (f y) instance Functor f => OK x (f y) but I'm not allowed class Bad x y z | x y -> z instance Functor f => Bad (f x) (f y) Bool instance Functor f => Bad x (f y) Int I don't quite see wh

Re: container for different types, avoiding boiler plate

2003-08-21 Thread Markus . Schnell
After taking a look at Data.Dynamic I came up with: > data Gender = Masc | Fem | Neutr deriving (Typeable, Show) > data Number = First | Second | Third deriving (Typeable, Show) > > type Attrs = [Dynamic] > > attrs = [toDyn Masc, toDyn Second] > > gattr :: (Typeable a) => Attrs -> Maybe a