2017. május 9., kedd

Rename definition refactoring

To rename a definition, select one of the occurrences. All occurrences (even in other modules) of the selected name will be renamed. Every Haskell definition (function, type, variable, constructor, field, typeclass, etc...) can be renamed.

f :: (Num a, Integral a) => a -> a -> a
f a b = (a + b) `div` 2

g :: Point -> Point -> Point
g p1 p2 = Point (f (x p1) (x p2)) (f (y p1) (y p2))

After renaming f to avg all occurrences are replaced:

avg :: (Num a, Integral a) => a -> a -> a
avg a b = (a + b) `div` 2

g :: Point -> Point -> Point
g p1 p2 = Point (avg (x p1) (x p2)) (avg (y p1) (y p2))

Rename definitions supports the GHC extension DuplicateRecordFields, so it can select the renamed field of multiple fields with the same name. It also supports RecordWildCards, so implicit bindings of fields will also be renamed. Modules can also be refactored, however the .cabal files are not updated automatically.

Nincsenek megjegyzések:

Megjegyzés küldése