[Haskell-cafe] pattern matching on data families constructors
Francesco Mazzoli
f at mazzo.li
Thu Apr 25 22:08:56 CEST 2013
At Thu, 25 Apr 2013 19:08:17 +0100,
Francesco Mazzoli wrote:
> Would you expect this to work?
>
> > newtype DInt a = DInt a
> > newtype DBool a = DBool a
> >
> > type family D a
> > type instance D Int = DInt Int
> > type instance D Bool = DBool Bool
> >
> > a :: D a -> a
> > a (DInt x) = x
> > a (DBool x) = x
Or even better:
> data family D a
> data instance D Int = DInt1 Int | DInt2 Int
> data instance D Bool = DBool Bool
>
> a :: D a -> a
> a (DInt1 x) = x
> a (DInt2 x) = x
> a (DBool x) = x
Francesco
More information about the Haskell-Cafe
mailing list