Identity: AddConstructor

Category: Data MultiModule

Classifiers: constructor definition

Internal cross references:

External cross references:

Language: Haskell

```
data Expr = Plus Expr Expr | Minus Expr Expr
eval :: Expr -> Int
eval (Plus e1 e2) = (eval e1) + (eval e2)
eval (Minus e1 e2) = (eval e1) - (eval e2)
``` | ```
data Expr = Plus Expr Expr | Minus Expr Expr | Var Int
addedVar = error "added Var Int to Expr"
eval :: Expr -> Int
eval (Plus e1 e2) = (eval e1) + (eval e2)
eval (Minus e1 e2) = (eval e1) - (eval e2)
eval (Var a) = addedVar
``` |

General comment:

New patterns are added to case analyses that recurse over the data type in question. The positioning of the new pattern is placed preserving the order that it was defined in the data type.

Left to right comment:

The value given as a new constructor in this example is
`Var Int`

and is added as the last constructor of the
`Expr`

data type. New patterns are added to capture the new constructor
and the RHS of the pattern matches call a function raising an error.

Right to left comment:

An argument can only be removed if it is not used anywhere in the program. If the binding is exported to other modules in a multi-module system, it is necessary to check uses throughout the system.

Left to right conditions:

Adding the new formal parameter should not capture any existing uses of constructor names within that data type.

Right to left conditions:

The constructor must not be used any where in the program.

Analysis required: