container for different types, avoiding boiler plate
Hal Daume
t-hald@microsoft.com
Thu, 21 Aug 2003 08:12:16 -0700
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=20
> [mailto:Markus.Schnell@infineon.com]=20
> 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
>=20
>=20
> After taking a look at Data.Dynamic I came up with:
>=20
> > data Gender =3D Masc | Fem | Neutr deriving (Typeable, Show)
> > data Number =3D First | Second | Third deriving (Typeable, Show)
> >
> > type Attrs =3D [Dynamic]
> >
> > attrs =3D [toDyn Masc, toDyn Second]
> >
> > gattr :: (Typeable a) =3D> Attrs -> Maybe a =20
> > gattr [] =3D Nothing
> > gattr (x:xs) =3D case fromDynamic x of
> > Nothing -> gattr xs
> > Just x -> Just x
> >
> > type GetAttr a =3D Attrs -> Maybe a
> > ggender =3D gattr :: GetAttr Gender
> > gnumber =3D gattr :: GetAttr Number
>=20
> which already is much more readable. But I'm sure
> problems are just around the corner ...
>=20
> Thank you.
> Markus
>=20
>=20