Suppose you have a nice inductive definition and you want to define it as a data type in Haskell. However, your inductive definition is (as many inductive definitions are) of such a form that the generating rules require their 'premisses' to have a certain structure. For instance, suppose we have the following definition:
- if
xis an even integer, thenT xis a weapon, - if
xis an odd integer, thenS xis a weapon.
If I want to define this (as a single) data type in Haskell, I would write something like
data Weapon = T Int | S Int
Obviously, this will not work as you now can generate T 5 and S 4, for instance. Is there a natural way to pass on restrictions on the constructor arguments, so that I could write something similar to the above code which would give the correct definition?
TandSdirectly, and createnewTandnewSfunctions that verify the numbers passed.