[Haskell-cafe] A question about data declaration

Brent Yorgey byorgey at seas.upenn.edu
Thu Mar 21 16:28:31 CET 2013


On Thu, Mar 21, 2013 at 06:18:46PM +0530, C K Kashyap wrote:
> Hi,
> 
> I have a situation where I need to define a data type T such that
> 
> data T = C1 Int | C2 Char | C3 T
> 
> However, I want to enforce a constraint that C3 only allows (C2 Char) and
> not (C1 Int). That is

If C3 should only be able to hold a C2 Char, then why have it hold a T
at all?  i.e. why not

  data T = C1 Int | C2 Char | C3 Char

but I suppose your real problem is probably more complicated, in which
case I would recommend using a GADT as others have suggested.

-Brent



More information about the Haskell-Cafe mailing list