Re: container for different types, avoiding boiler plate
21 Aug
2003
21 Aug
'03
8:58 a.m.
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
8408
Age (days ago)
8408
Last active (days ago)
0 comments
1 participants
participants (1)
-
Markus.Schnell@infineon.com