Yes, this is essentially what DynamicMap is....The 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 > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] > Sent: Thursday, August 21, 2003 1:58 AM > To: [EMAIL PROTECTED] > Cc: Hal Daume; [EMAIL PROTECTED] > Subject: Re: container for different types, avoiding boiler plate > > > 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 > > gattr [] = Nothing > > gattr (x:xs) = case fromDynamic x of > > Nothing -> gattr xs > > Just x -> Just x > > > > type GetAttr a = Attrs -> Maybe a > > ggender = gattr :: GetAttr Gender > > gnumber = gattr :: GetAttr Number > > which already is much more readable. But I'm sure > problems are just around the corner ... > > Thank you. > Markus > > _______________________________________________ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
