UMinho Haskell Libraries (2004.07.02)ContentsIndex
Data.Relation.TypeInference
Portability portable
Stability experimental
Maintainer joost.visser@di.uminho.pt
Contents
Representation
Inference of a type graph.
Inference of types (groups of variables).
Helper
Description

An implementation of the type reconstuction algorithm from

  • Arie van Deursen and Leon Moonen, An Empirical Study into Cobol type inferencing. In Science of Computer Programming, 40(2-3):189-211, July 2001.
Synopsis
type VariableGraph v array = (Rel v v, Rel v array, Rel v v)
type TypeGraph x = (Rel x x, Rel x x)
typeInference :: (Ord v, Ord array) => VariableGraph v array -> TypeGraph v
typeInferenceLoop :: Ord x => TypeGraph x -> TypeGraph x
types :: Ord x => Rel x x -> [Set x]
repeatUntilFixpoint :: Eq a => (a -> a) -> a -> a
Representation
type VariableGraph v array = (Rel v v, Rel v array, Rel v v)

A variable graph is a 3-tuple of three relations:

  • expression: equivalence relation between variables based on occurance in the same expression.
  • array: relation between index variables and array variables.
  • assign: relation between variables based on assignment of one to the other.
type TypeGraph x = (Rel x x, Rel x x)
A type graph is a tuple of two relations: a type equivalence relation, and a subtype relation.
Inference of a type graph.
typeInference :: (Ord v, Ord array) => VariableGraph v array -> TypeGraph v
The main function for type inference. It computes a type graph on the basis of a variable graph.
typeInferenceLoop :: Ord x => TypeGraph x -> TypeGraph x
The loop function for type inference. Starting from an initial type graph, it iteratively derives a more accurate type graph until a fixpoint occurs.
Inference of types (groups of variables).
types :: Ord x => Rel x x -> [Set x]
Derive a list of equivalence classes from an equivalence relation. If the relation is a type equivalence relation over variables, the equivalence classes are groups of variables, i.e. types.
Helper
repeatUntilFixpoint :: Eq a => (a -> a) -> a -> a
Keep applying the argument function until the output equals the input, i.e. until a fixpoint is reached.
Produced by Haddock version 0.6