Why? Because you can only answer constructors, and exec is a new variable. One reason for this is, for example, the following:
data Struct2 = Empty | Exec1 String | Exec2 Int apply :: Struct2 -> String apply Empty = "matched Empty" apply (exec struct) = ??
How to find out which of Exec1 and Exec2 do you match? You cannot apply functions here, since the actual type of struct cannot be defined.
If you want to reduce the correspondence of templates, there are several ways: from using case , from another data implementation (for example, proposed by K. Karolis) and auxiliary functions to higher-level constructions with more complex types. But this is an endless topic.
phg
source share