Module AbstractHaskell.Types

This library contains a definition for representing Haskell programs in Curry (type "Prog").

Author: Michael Hanus, Björn Peemöller

Version: May 2017

Summary of exported operations:

Exported datatypes:


Prog

Data type for representing a Haskell module in the intermediate form. A value of this data type has the form

(CProg modname imports typedecls functions opdecls)

where modname: name of this module, imports: list of modules names that are imported, typedecls, opdecls, functions: see below

Constructors:


QName

The data type for representing qualified names. In AbstractHaskell all names are qualified to avoid name clashes. The first component is the module name and the second component the unqualified name as it occurs in the source program.

Type synonym: QName = (String,String)


Visibility

Data type to specify the visibility of various entities.

Constructors:

  • Public :: Visibility
  • Private :: Visibility

TVarIName

The data type for representing type variables. They are represented by (i,n) where i is a type variable index which is unique inside a function and n is a name (if possible, the name written in the source program).

Type synonym: TVarIName = (Int,String)


TypeDecl

Data type for representing definitions of algebraic data types and type synonyms.

A data type definition of the form

data t x1...xn = ...| c t1....tkc |...

is represented by the Curry term

(Type t v [i1,...,in] [...(ons c kc v [t1,...,tkc])...])

where each ij is the index of the type variable xj.

Note: the type variable indices are unique inside each type declaration and are usually numbered from 0

Thus, a data type declaration consists of the name of the data type, a list of type parameters and a list of constructor declarations.

Constructors:


Context

A single type context is class name applied to type variables.

Constructors:


ConsDecl

A constructor declaration consists of the name and arity of the constructor and a list of the argument types of the constructor.

Constructors:


NewConsDecl

A constructor declaration for a newtype consists of the name of the constructor and the argument type of the constructor.

Constructors:


TypeExpr

Data type for type expressions. A type expression is either a type variable, a function type, or a type constructor application.

Note: the names of the predefined type constructors are "Int", "Float", "Bool", "Char", "IO", "()" (unit type), "(,...,)" (tuple types), "[]" (list type)

Constructors:


Kind

Constructors:

  • KindStar :: Kind
  • KindArrow :: Kind -> Kind -> Kind

TypeSig

Data type to represent the type signature of a defined function. The type can be missing or a type with an optional context.

Constructors:


OpDecl

Data type for operator declarations. An operator declaration "fix p n" in Haskell corresponds to the AbstractHaskell term (Op n fix p).

Constructors:


Fixity

Constructors:

  • InfixOp :: Fixity
  • InfixlOp :: Fixity
  • InfixrOp :: Fixity

VarIName

Data types for representing object variables. Object variables occurring in expressions are represented by (Var i) where i is a variable index.

Type synonym: VarIName = (Int,String)


FuncDecl

Data type for representing function declarations.

A function declaration in AbstractHaskell is a term of the form

(Func cmt name arity visibility type (Rules eval [Rule rule1,...,rulek]))

and represents the function name defined by the rules rule1,...,rulek.

Note: the variable indices are unique inside each rule

External functions are represented as

(Func cmt name arity type External)

Thus, a function declaration consists of the comment, name, arity, type, and a list of rules. The type is optional according to its occurrence in the source text. The comment could be used by pretty printers that generate a readable Haskell program containing documentation comments.

Constructors:


Rules

Rules are either a list of single rules or no rule at all if then function is defined externally.

Constructors:

  • Rules :: [Rule] -> Rules
  • External :: Rules

Rule

The most general form of a rule. It consists of a list of patterns (left-hand side), a list of guards ("True" if not present in the source text) with their corresponding right-hand sides, and a list of local declarations.

Constructors:


Rhs

Constructors:

  • SimpleRhs :: Expr -> Rhs
  • GuardedRhs :: [(Expr,Expr)] -> Rhs

LocalDecl

Data type for representing local (let/where) declarations

Constructors:


Expr

Data type for representing Haskell expressions.

Constructors:


Statement

Data type for representing statements in do expressions and list comprehensions.

Constructors:


Pattern

Data type for representing pattern expressions.

Constructors:


BranchExpr

Data type for representing branches in case expressions.

Constructors:


Literal

Data type for representing literals occurring in an expression. It is either an integer, a float, a character, or a string constant.

Constructors:

  • Intc :: Int -> Literal
  • Floatc :: Float -> Literal
  • Charc :: Char -> Literal
  • Stringc :: String -> Literal

Exported operations: