Table of Contents

Go to: Tool Homepage - Downloads - User Guide - Examples

Reference for Operations

HaRe "Introduce new def"

Interfaces to HaRe "Introduce New Def" refactoring operation

These functions are interfaces to the HaRe Introduce New Def refactoring operation.

newDefEqBodyIn (exhibitFunction in v0.1)

Introduce a new definition for the body of an equation of a given declaration.

newDefEqBodyIn f constr newname mod: In the declaration of a function f inthe module mod, select the equation where the constructor constr occurs in the pattern, and replace the body b of this equation by newname where newname = b (call to HaRe Introduce New Def on the body expression b).

Note : the behavior is unspecified when several constructors occur in a pattern or when a same constructor occurs in several patterns.

newDefIdentAppN

Introduce a new definition for an application of a given identifier to a given number of arguments.

newDefIdentAppN f n newname mod: find in module mod an application of the identifier f to n arguments and introduce an new binding of that expression to newname (call to HaRe Introduce New Def on the application). If f is applied to more than n arguments, the subexpression where f is applied to exactly n arguments is selected.

Note : if there is no occurence of an application of f to at least n arguments, then (to be completed).

Note : if more thant one occurence of such an application is found, then (to be completed).

Note : a tuple as argument is counted as a single argument.

newDefIdentApp

Same as newDefIdentAppN except that the number of parameters passed to the applied function is not given: newDefIdentApp f newname mod

newDefIdentAppIn (newDefFunAppIn in v0.1)

Same as newDefIdentApp but the occurence of a convenient application is searched in a given function.

newDefIdentAppIn g f n newname mod: in the top-level definition of g in module mod, find an application of the identifier f to n arguments and introduce an new binding of that expression to newname (call to HaRe Introduce New Def on the application).

See newDefIdentApp for more details.

newDefIdentAppToIn (newDefFunAppInTo in v0.1)

(to be completed)

newDefIdentIn

(to be completed)

newDefInfixAppIn

(to be completed)

Chains

The operation below is a chain: it can make several calls to the HaRe Introduce New Def refactoring operation.

newDefAllEqBodiesIn

newDefAllEqBodiesIn f mod introduces local definitions for the bodies of each equation of the top-level definition of f in the module mod.

HaRe "Generalise def"

Interfaces

generalise f c f' m n x curry "OtherType" (renamed into generalisePatternVariableInLocalDefIn in v0.2)

In the module m, in the equation concerning the constructor c of the definition of f, let v be the nth argument of the constructor c in the pattern of the equation, generalise v in the local definition of f' and name x the new argument.

The flag curry indicates whether the arguments of the constructor are curried or not to count the arguments.

generalise f c f' m n x curry "RecType" (renamed into generaliseRecAppToPatternVariableInLocalDefIn in v0.2)

In the module m, in the equation concerning the constructor c of the definition of f, let v be the nth argument of the constructor c in the pattern of the equation, generalise an application of f to v in the local definition of f' and name x the new argument.

generaliseIdent f m v x (renamed into generaliseIdentIn in v0.2)

In the definition of f in the module m, generalise the variable v and name the new parameter x.

generaliseIdentAppIn f g n a m

In the toplevel definition of f in module m, generalise an application of g to n arguments, and name it a.

generaliseArgIdentIn f g n a m

In the toplevel definition of f in module m, generalise an instance of n in an application of g, and name it a.

generalise2

Not used anymore since v0.2.

Chains

generaliseAllPatternVariablesInAllLocalDefsIn

generaliseAllRecAppToPatternVariablesInAllLocalDefsIn

generaliseAllRecAppToPatternVariablesInAllLocalDefsIn f prefix mod: In the recursive toplevel definition of f in the module mod, select expressions which are applications of f to some arguments (as many as possible) which occur inside local declarations which defined ident is prefixed by prefix, and genrealise them (in the local definitions).

generaliseIdentInAllLocalDefsIn

generaliseAllIdentsTopLevel

generaliseAllIdentsTopLevel f prefix newprefix mod: Generalise all idents starting with prefix in the toplevel declaration of f in mod. Resulting new parameters are named with newprefix suffixed with an integer.

HaRe "Lift def to top level", "Lift def one level" and "Demote def"

Interfaces

makeGlobalOfLocalIn f d m (renamed into liftDefToTopLevelIn in v0.2)

Lift the definition of d at the top-level. d is declared inside the definition of f in the module m.

makeGlobalOfLocal (renamed into liftDefToTopLevel in v0.2)

liftOneLevelIn

demoteTopLevel f mod

demoteIn f g mod

Chains

liftAllLocalDefsToTopLevelIn

HaRe "Rename"

Interfaces

renameToplevel f m f' (renamed into renameTopLevelIdent in v0.2)

Rename t declared at the top-level in the module m into f' .

renameLocal (renamed into renameLocalIdentIn in v0.2)

Chains

renameAllIdentsIn f prefix mod

Find in the top-level declaration of f all the identifiers starting with prefix and rename them into f. Qualifiers will be inserted if necessary (by HaRe). All the new names are the same (ok if they are defined in separate modules).

renameAllIdentsIn2 funname targetname newprefix funmod

Find in the top-level declaration of funname in funmod all the identifiers named targetname (possibly with different qualifiers) and rename them with different names starting with the given prefix newprefix. All the new names are different (with a same prefix). If funname and targetname are the same, the occurences refering to the toplevel function being handled will not be renamed.

Replace

This operation does not come from HaRe, it is provided with Haskell View Switcher. We explain the IDE interface and the Emacs-Lisp interfaces.

In the IDE

(Experimental) Replace an occurence of an identifier f by an identifier g where f and g are alpha-equivalent functions declared at the top-level. The notion of alpha-equivalence is rather ad-hoc (see the source code).

Select the occurence of the identifier to replace before choosing Refactor > Ad-hoc refactorings > Replace item in the menu.

replaceIdentIn f d m g

(Experimental) Replace an occurence of an identifier f in the declaration of d in the module m by the identifier g where f and g are alpha-equivalent functions declared at the top-level. The notion of alpha-equivalence is rather ad-hoc (see the source code).

HaRe "Move def to another module"

Interfaces

moveDefBetweenModules f m m'

Move the top-level definition of f from module m to module m' .

Chains

moveAllDefsToConstructorModulesFollowingPatternMatching

moveAllDefsOnSuffix prefix mod

Move all toplevel definitions with a given prefix into modules determined by the suffix of the name defined. For example, prefix_Suffix will be moved to SuffixMod.

HaRe "Unfold def" and "Fold definition"

Interfaces

unfoldInstanceIn d f m (renamed into unfoldIn in v0.2)

Replace an instance of the identifier d by the boy of its definition, in the body of f in module m. If possible, a beta-reduction is applied (see the corresponding HaRe operation).

foldTopLevelDefinition f m

Fold the definition of function f of module m (see the corresponding HaRe operation).

HaRe "Generative Fold"

Interfaces

generativeFold f i m (renamed into generativeFoldIdentApp in v0.2)

Select an application of the identifier f to i arguments in m and apply HaRe Generative Fold operation on it (a comment must be present before the affected declaration, see the HaRe operation).

Chains

generativeFoldAllIdentAppIn f g mod

Apply a generative fold on applications of g in the top-level declaration of f in mod.

HaRe "Remove def"

removeDefCmd f m (renamed into removeTopLevelDef in v0.2)

Remove the definition of f in the module m. f must not be used elsewhere.

removeLocalDef d f m (renamed into removeLocalDefIn in v0.2)

Remove the definition of d which is local to f in the module m. f must not be used elsewhere.

HaRe "Clean imports" and "Remove from export"

cleanImportsCmd m (renamed into cleanImportsMod in v0.2)

Call the Clean imports operation on the module m (remove the useless imports).

rmFromExports f m (renamed into rmFromExportsMod in v0.2)

Remove f from the explicit exports of the module m. f must not be used in an other module.

Add implicit import

This operation does not come from HaRe, it is shipped with View Switcher.

addImplicitImportUnsafe cmod fmod

Add in cmod an import directive for fmod. The imported identifers are left implicit. If a potential name clash is detected, the import is made “qualified”.

Warning: This operation is under development and can break the semantics of your program. In particular, the prerequesites to allow the import to be unqualified are not validated.

Case Pattern Matching

These operations are not provided by HaRe but are shipped with View Switcher.

Simplify a case pattern matching

This operation performs the following transformation (left to right):

case (e1, e2, e3) of
         (y, p11, p12) -> b1
         (y, p21, p22) -> b2
let y = e1
in case (e2, e3) of
            (p11, p12) -> b1
            (p21, p22) -> b2

Pre-condition : y is not free in e1, e2, or e3 (warning, this is not checked by the implementation currently).

The patterns and the matched expression have to be tuples.

The refactoring applies when there is a same identifier at the same position in all the pattern tuples.

Interactive usage:

Input: select the whole case expression.

Scripted usage (simplifyCasePattern)

simplifyCasePattern f m: Apply the above operation on a case expression in the definition of f in the module m.

(to be renamed into simplifyCasePatternIn in v0.2)

Repeat (repeatSimplifyCasePatternIn)

This is an heterogeneous chain : it chains simplifications and deletions (within the meaning of the “forget” operation below) of the introduced local definitions.

repeatSimplifyCasePatternIn f1 clientmod: Repeat simplifications and deletions in the top-level declaration of f in mod.

Transform a case pattern matching into equations

This operation performs the following transformation (left to right):

f x = case (x) of
            p1 -> e1
            p2 -> e2
f p1 = e1
f p2 = e2

Also:

f x y = case (x,y) of
            (p11,p12) -> e1
            (p21,p22) -> e2
f p11 p12 = e1
f p21 p22 = e2
Scripted usage (caseToEqIn)

caseToEqIn f m: Select the case expression which is at the top-level of the body of the declaration of f in the module m and transform it into a set of equations.

(caseToEq in v0.1)

Comments

These operations are not provided by HaRe but are shipped with View Switcher.

Copy a declaration into a comment

Makes a copy of a declaration into a comment placed just above the declaration (to be used before applying Generative Fold).

Scripted usage: duplicateTopLevelDefIntoComment

duplicateTopLevelDefIntoComment f m: Copy the declaration of f of the module m.

(duplicateIntoComment in v0.1)

Remove a comment

Deletes a comment.

Scripted usage: rmCommentBeforeTopLevelDef

rmCommentBeforeTopLevelDef f m: Delete the comment occurring before the declaration of f at the top-level of the module m.

(rmCommentBefore in v0.1)

Forget (Heterogeneous Chains)

To forget a non-recursive definition consists in unfolding it wherever it is referenced, removing it from imports/exports, and deleting it.

forgetTopLevelPrefixed

forgetTopLevelPrefixed prefix mod: forget (as defined above) all top-level declarations of idents starting with prefix in module mod.

forgetAllTopLevelIdentWithOccurenceIn f1 f1prefix clientmod