RE: container for different types, avoiding boiler plate
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 | hdaume@isi.edu "Arrest this man, he talks in maths." | www.isi.edu/~hdaume
-----Original Message----- From: Markus.Schnell@infineon.com [mailto:Markus.Schnell@infineon.com] Sent: Thursday, August 21, 2003 1:58 AM To: haskell@haskell.org Cc: Hal Daume; ddarius@hotpop.com 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
participants (1)
-
Hal Daume