I want to make a data type Var which represents a variable. A variable is a character that is a, b, c… z, lowercase or uppercase.
I can write this:
data Var = A | B | C -- continues to Z
but I can’t write this:
data Var = a | b | c -- continues to z
Presumably because they are lowercase. Is there an elegant way to make this data type?
One solution is to simply have
While
Var 'c'andVar 'D'will populate the type as desired, unfortunatelyVar '%'can populate it as well. There are two ways to fix this. One is to enumerate all constructors as you did:The other way to only let correct values get into the type is to use smart constructors.