This library contains a definition for representing Curry programs in Curry.
Note this defines a slightly new format for AbstractCurry in comparison to the first proposal of 2003.
Assumption: an abstract Curry program is stored in file with extension .acy
Author: Michael Hanus, Bjoern Peemoeller, Finn Teegen
Version: October 2016
version
:: String
Current version of AbstractCurry |
preludeName
:: String
The name of the standard prelude. |
pre
:: String -> (String,String)
Converts a string into a qualified name of the Prelude. |
A module name.
Type synonym: MName = String
The data type for representing qualified names. In AbstractCurry 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. An exception are locally defined names where the module name is the empty string (to avoid name clashes with a globally defined name).
Type synonym: QName = (MName,String)
Data type to specify the visibility of various entities.
Constructors:
Public
:: CVisibility
Private
:: CVisibility
Data type for representing a Curry module in the intermediate form. A value of this data type has the form
(CurryProg modname imports dfltdecl clsdecls instdecls typedecls funcdecls opdecls)
where modname: name of this module, imports: list of modules names that are imported, dfltdecl: optional default declaration clsdecls: Class declarations instdecls: Instance declarations typedecls: Type declarations functions: Function declarations opdecls: Operator precedence declarations
Constructors:
CurryProg
:: MName -> [MName] -> (Maybe CDefaultDecl) -> [CClassDecl] -> [CInstanceDecl] -> [CTypeDecl] -> [CFuncDecl] -> [COpDecl] -> CurryProg
Data type for representing default declarations.
Constructors:
CDefaultDecl
:: [CTypeExpr] -> CDefaultDecl
Data type for representing classes declarations.
A type class definition of the form
class cx => c a where { ...;f :: t;... }
is represented by the Curry term
(CClass c v cx tv [...(CFunc f ar v t [...,CRule r,...])...])
where tv
is the index of the type variable a
and v
is the
visibility of the type class resp. method.
Note: The type variable indices are unique inside each class
declaration and are usually numbered from 0.
The methods' types share the type class' type variable index
as the class variable has to occur in a method's type signature.
The list of rules for a method's declaration may be empty if
no default implementation is provided. The arity ar
is
determined by a given default implementation or 0.
Regardless of whether typed or untyped abstract curry is generated,
the methods' declarations are always typed.
Constructors:
CClass
:: QName -> CVisibility -> CContext -> CTVarIName -> [CFuncDecl] -> CClassDecl
Data type for representing instance declarations.
An instance definition of the form
instance cx => c ty where { ...;fundecl;... }
is represented by the Curry term
(CInstance c cx ty [...fundecl...])
Note: The type variable indices are unique inside each instance declaration and are usually numbered from 0. The methods' types use the instance's type variable indices (if typed abstract curry is generated).
Constructors:
Data type for representing definitions of algebraic data types and type synonyms.
A data type definition of the form
data t x1...xn = ...| forall y1...ym . cx => c t1....tkc |... deriving (d1,...,dp)
is represented by the Curry term
(CType t v [i1,...,in] [...(CCons [l1,...,lm] cx c kc v [t1,...,tkc])...] [d1,...,dp]))
where each ij
is the index of the type variable xj
, each lj
is the
index of the existentially quantified type variable yj
and v
is the
visibility of the type resp. constructor.
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:
CType
:: QName -> CVisibility -> [CTVarIName] -> [CConsDecl] -> [QName] -> CTypeDecl
CTypeSyn
:: QName -> CVisibility -> [CTVarIName] -> CTypeExpr -> CTypeDecl
CNewType
:: QName -> CVisibility -> [CTVarIName] -> CConsDecl -> [QName] -> CTypeDecl
The 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: CTVarIName = (Int,String)
A constructor declaration consists of a list of existentially quantified type variables, a context, the name of the constructor and a list of the argument types of the constructor. The arity equals the number of types.
Constructors:
CCons
:: [CTVarIName] -> CContext -> QName -> CVisibility -> [CTypeExpr] -> CConsDecl
CRecord
:: [CTVarIName] -> CContext -> QName -> CVisibility -> [CFieldDecl] -> CConsDecl
A record field declaration consists of the name of the the label, the visibility and its corresponding type.
Constructors:
CField
:: QName -> CVisibility -> CTypeExpr -> CFieldDecl
Class constraint.
Type synonym: CConstraint = (QName,CTypeExpr)
Context.
Constructors:
CContext
:: [CConstraint] -> CContext
Type expression. 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:
CTVar
:: CTVarIName -> CTypeExpr
CFuncType
:: CTypeExpr -> CTypeExpr -> CTypeExpr
CTCons
:: QName -> CTypeExpr
CTApply
:: CTypeExpr -> CTypeExpr -> CTypeExpr
Qualified type expression.
Constructors:
Labeled record fields
Type synonym: CField a = (QName,a)
Data type for operator declarations. An operator declaration "fix p n" in Curry corresponds to the AbstractCurry term (COp n fix p).
Constructors:
Data type for operator associativity
Constructors:
CInfixOp
:: CFixity
CInfixlOp
:: CFixity
CInfixrOp
:: CFixity
Function arity
Type synonym: Arity = Int
Data type for representing function declarations.
A function declaration in AbstractCurry is a term of the form
(CFunc name arity visibility type (CRules eval [CRule rule1,...,rulek]))
and represents the function name
defined by the rules
rule1,...,rulek
.
Note: the variable indices are unique inside each rule
Thus, a function declaration consists of the name, arity, type, and
a list of rules. The type is the function's type inferred by the
type checker. However, if an AbstractCurry program is read with
the operation AbstractCurry.Files.readUntypedCurry
, the type
is either the type signature provided by the programmer or
the expression (CTCons ("Prelude","untyped")
if the programmer has not provided an explicit type signature.
A function declaration with the constructor CmtFunc
is similarly to CFunc
but has a comment
as an additional first argument. This comment could be used
by pretty printers that generate a readable Curry program
containing documentation comments.
Constructors:
CFunc
:: QName -> Arity -> CVisibility -> CQualTypeExpr -> [CRule] -> CFuncDecl
CmtFunc
:: String -> QName -> Arity -> CVisibility -> CQualTypeExpr -> [CRule] -> CFuncDecl
The general form of a function rule. It consists of a list of patterns (left-hand side) and the right-hand side for these patterns.
Constructors:
Right-hand-side of a CRule
or a case
expression.
It is either a simple unconditional right-hand side or
a list of guards with their corresponding right-hand sides, and
a list of local declarations.
Constructors:
CSimpleRhs
:: CExpr -> [CLocalDecl] -> CRhs
CGuardedRhs
:: [(CExpr,CExpr)] -> [CLocalDecl] -> CRhs
Data type for representing local (let/where) declarations
Constructors:
CLocalFunc
:: CFuncDecl -> CLocalDecl
CLocalPat
:: CPattern -> CRhs -> CLocalDecl
CLocalVars
:: [CVarIName] -> CLocalDecl
Data types for representing object variables. Object variables occurring in expressions are represented by (Var i) where i is a variable index.
Type synonym: CVarIName = (Int,String)
Data type for representing pattern expressions.
Constructors:
CPVar
:: CVarIName -> CPattern
CPLit
:: CLiteral -> CPattern
CPComb
:: QName -> [CPattern] -> CPattern
CPAs
:: CVarIName -> CPattern -> CPattern
CPFuncComb
:: QName -> [CPattern] -> CPattern
CPLazy
:: CPattern -> CPattern
CPRecord
:: QName -> [CField CPattern] -> CPattern
Data type for representing Curry expressions.
Constructors:
CVar
:: CVarIName -> CExpr
CLit
:: CLiteral -> CExpr
CSymbol
:: QName -> CExpr
CApply
:: CExpr -> CExpr -> CExpr
CLambda
:: [CPattern] -> CExpr -> CExpr
CLetDecl
:: [CLocalDecl] -> CExpr -> CExpr
CDoExpr
:: [CStatement] -> CExpr
CListComp
:: CExpr -> [CStatement] -> CExpr
CCase
:: CCaseType -> CExpr -> [(CPattern,CRhs)] -> CExpr
CTyped
:: CExpr -> CQualTypeExpr -> CExpr
CRecConstr
:: QName -> [CField CExpr] -> CExpr
CRecUpdate
:: CExpr -> [CField CExpr] -> CExpr
Data type for representing literals occurring in an expression. It is either an integer, a float, or a character constant.
Constructors:
CIntc
:: Int -> CLiteral
CFloatc
:: Float -> CLiteral
CCharc
:: Char -> CLiteral
CStringc
:: String -> CLiteral
Data type for representing statements in do expressions and list comprehensions.
Constructors:
CSExpr
:: CExpr -> CStatement
CSPat
:: CPattern -> CExpr -> CStatement
CSLet
:: [CLocalDecl] -> CStatement
Type of case expressions
Constructors:
CRigid
:: CCaseType
CFlex
:: CCaseType
Current version of AbstractCurry
|
The name of the standard prelude.
|
Converts a string into a qualified name of the Prelude.
|