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
x
is an even integer, thenT x
is a weapon, - if
x
is an odd integer, thenS x
is 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?
T
andS
directly, and createnewT
andnewS
functions that verify the numbers passed. – Tala