[Haskell-cafe] A question about data declaration

C K Kashyap ckkashyap at gmail.com
Thu Mar 21 13:48:46 CET 2013


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

x = C3 (C1 10) -- should not compile - but my above definition will let it
compile


I was thinking of this -

data C1 = C1 Int
data C2 = C2 Char
data T = TC1 C1 | TC1 C2 | TC3 C2

Is there a better way to do it?

Regards,
Kashyap
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130321/30e411cc/attachment.htm>


More information about the Haskell-Cafe mailing list