[Haskell-cafe] an automatic refactoring idea
jeffbrown.the at gmail.com
Thu Jan 21 08:08:42 UTC 2016
I had a data structure with a redundant field . I refactored to make
that field go away. Here is the code . The following is a simplification
I was using this type:
data X = X1 | X2 Int
To make the Int go away, I made a duplicate type:
data X' = X1' | X2'
Then, every function for which any argument was of type X, I similarly
duplicated, replacing every X with X', X1 for X1', and X2 for X2'. Next I
had to similarly duplicate every function that used one of those. And so
on, and so on ... until eventually I was duplicating the tests. At that
point I was able to determine from the duplicate tests that everything was
There was a little more work involved than that, but the vast, vast
majority of the edits that got me there were the simple duplication I just
I looked once at automatic refactoring in Haskell and was either
unimpressed or scared. I may not have understood what I was looking at
enough to appreciate its power. Is there something that can do the
refactoring described above?
 The Int in a Tplt could be inferred from context, so keeping a
duplicate of that information in the Tplt was dangerous, because it makes
invalid state possible (e.g. if one is updated and not the other). So I
decided to stop using it.
Jeffrey Benjamin Brown
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe