I have just finished the first version of my refactoring which uses type information to check which functions need pattern binding. This means you can have the declaration:

f :: New -> Int
f x = 45

and the refactoring will add

f :: New -> Int
f (Con2 x) = addedCon2
f x = 45

I have found something very fascinating:

ht (Con2 a b) = addedCon2
ht x
= case x of
(Con1 y) -> y
_ -> 44

In the above example the refactoring added the pattern at the top level declaration, because x is of type New. This is acceptable but I feel there is an alternative and that is to add in the case pattern. There are a nember of ways to deal with this:

1) always add to the top level
2) always add to the case pattern (but not the top level)
3) add to both the top level and the case patterns (belt and braces)

1 or 3 are the easiest to implement.

TODO: remove the hardcoded "New" data type!