Identity: Merging

Category: Data MultiModule

Classifiers: Merging definition

Internal cross references:

External cross references:

Language: Haskell

```
{- f1 :: Num t1 => ( t1 -> t ) -> t1 -}
f1 1 x = 1
f1 x y = x + 1
{- f2 :: Num t => ( t -> t1 ) -> t1 -}
f2 1 x = x
f2 x y = y
``` | ```
f 1 x = (1, x)
f x y = (x + 1, y)
{- f1 :: Num t1 => ( t1 -> t ) -> t1 -}
f1 1 x = 1
f1 x y = x + 1
{- f2 :: Num t => ( t -> t1 ) -> t1 -}
f2 1 x = x
f2 x y = y
``` |

General comment:

The use of sharing terms can be used as a form of code optimisation.

Left to right comment:

Function definitons are selected and added to a cache. A new definition is then created (with a user specified name) encapsulating the computation required for each selected function. Each function computation is returned as a separate element of a tuple, and any shared terms are unified.

Right to left comment:

This is defined in splitting. Splitting a function that returns in a tuple results in new function definitions; each nwe function definition encapuslates the computation required to compute a single tuple element.

Left to right conditions:

At least two definitions must be selected to perform the merge.

Right to left conditions:

The selected definition must return a tuple or a single value (as opposed to, say, a list).

Analysis required: