Library to support meta-programming in Curry.
This library contains a definition for representing Curry programs
in Curry (type "CurryProg") and an I/O action to read Curry programs and
transform them into this abstract representation (function "readCurry").
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
Version: July 2008
| Exported names: |
Datatypes:
CBranchExpr
| CConsDecl
| CEvalAnnot
| CExpr
| CFixity
| CFuncDecl
| CLiteral
| CLocalDecl
| COpDecl
| CPattern
| CRule
| CRules
| CStatement
| CTVarIName
| CTypeDecl
| CTypeExpr
| CurryProg
| CVarIName
| CVisibility
| QName
Constructors:
CApply
| CBranch
| CCase
| CCharc
| CChoice
| CCons
| CDoExpr
| CExternal
| CFlex
| CFloatc
| CFunc
| CFuncType
| CInfixlOp
| CInfixOp
| CInfixrOp
| CIntc
| CLambda
| CLetDecl
| CListComp
| CLit
| CLocalFunc
| CLocalPat
| CLocalVar
| CmtFunc
| COp
| CPAs
| CPComb
| CPFuncComb
| CPLit
| CPVar
| CRigid
| CRule
| CRules
| CSExpr
| CSLet
| CSPat
| CSymbol
| CTCons
| CTVar
| CType
| CTypeSyn
| CurryProg
| CVar
| Private
| Public
Functions:
readAbstractCurryFile
| readCurry
| readCurryWithParseOptions
| readUntypedCurry
| readUntypedCurryWithParseOptions
| writeAbstractCurryFile
| Summary of exported functions: |
|
||
|
||
|
||
|
||
|
||
|
| Imported modules: |
| Exported datatypes: |
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.
Type synonym: QName = (String,String)
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: CTVarIName = (Int,String)
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 a Curry 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:
:: String -> [String] -> [CTypeDecl] -> [CFuncDecl] -> [COpDecl] -> CurryProg
Constructors:
:: CVisibility
:: CVisibility
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
(CType t v [i1,...,in] [...(CCons 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:
:: (String,String) -> CVisibility -> [(Int,String)] -> [CConsDecl] -> CTypeDecl
:: (String,String) -> CVisibility -> [(Int,String)] -> CTypeExpr -> CTypeDecl
A constructor declaration consists of the name and arity of the constructor and a list of the argument types of the constructor.
Constructors:
:: (String,String) -> Int -> CVisibility -> [CTypeExpr] -> CConsDecl
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", "Success",
"()" (unit type), "(,...,)" (tuple types), "[]" (list type)
Constructors:
:: (Int,String) -> CTypeExpr
:: CTypeExpr -> CTypeExpr -> CTypeExpr
:: (String,String) -> [CTypeExpr] -> CTypeExpr
Data type for operator declarations. An operator declaration "fix p n" in Curry corresponds to the AbstractCurry term (COp n fix p).
Constructors:
:: (String,String) -> CFixity -> Int -> COpDecl
Constructors:
:: CFixity
:: CFixity
:: CFixity
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
External functions are represented as
(CFunc name arity type (CExternal s))
where s is the external name associated to this function.
Thus, a function declaration consists of the name, arity, type, and
a list of rules.
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:
:: (String,String) -> Int -> CVisibility -> CTypeExpr -> CRules -> CFuncDecl
:: String -> (String,String) -> Int -> CVisibility -> CTypeExpr -> CRules -> CFuncDecl
A rule is either a list of formal parameters together with an expression (i.e., a rule in flat form), a list of general program rules with an evaluation annotation, or it is externally defined
Constructors:
:: CEvalAnnot -> [CRule] -> CRules
:: String -> CRules
Data type for classifying evaluation annotations for functions. They can be either flexible (default), rigid, or choice.
Constructors:
:: CEvalAnnot
:: CEvalAnnot
:: CEvalAnnot
The most general form of a rule. It consists of a list of patterns (left-hand side), a list of guards ("success" if not present in the source text) with their corresponding right-hand sides, and a list of local declarations.
Constructors:
:: [CPattern] -> [(CExpr,CExpr)] -> [CLocalDecl] -> CRule
Data type for representing local (let/where) declarations
Constructors:
:: CFuncDecl -> CLocalDecl
:: CPattern -> CExpr -> [CLocalDecl] -> CLocalDecl
:: (Int,String) -> CLocalDecl
Data type for representing Curry expressions.
Constructors:
:: (Int,String) -> CExpr
:: CLiteral -> CExpr
:: (String,String) -> CExpr
:: CExpr -> CExpr -> CExpr
:: [CPattern] -> CExpr -> CExpr
:: [CLocalDecl] -> CExpr -> CExpr
:: [CStatement] -> CExpr
:: CExpr -> [CStatement] -> CExpr
:: CExpr -> [CBranchExpr] -> CExpr
Data type for representing statements in do expressions and list comprehensions.
Constructors:
:: CExpr -> CStatement
:: CPattern -> CExpr -> CStatement
:: [CLocalDecl] -> CStatement
Data type for representing pattern expressions.
Constructors:
:: (Int,String) -> CPattern
:: CLiteral -> CPattern
:: (String,String) -> [CPattern] -> CPattern
:: (Int,String) -> CPattern -> CPattern
:: (String,String) -> [CPattern] -> CPattern
Data type for representing branches in case expressions.
Constructors:
:: CPattern -> CExpr -> CBranchExpr
Data type for representing literals occurring in an expression. It is either an integer, a float, or a character constant.
Constructors:
:: Int -> CLiteral
:: Float -> CLiteral
:: Char -> CLiteral
| Exported functions: |
:: String -> IO CurryProg
I/O action which parses a Curry program and returns the corresponding typed Abstract Curry program. Thus, the argument is the file name without suffix ".curry" or ".lcurry") and the result is a Curry term representing this program.
:: String -> IO CurryProg
I/O action which parses a Curry program and returns the corresponding untyped Abstract Curry program. Thus, the argument is the file name without suffix ".curry" or ".lcurry") and the result is a Curry term representing this program.
:: String -> FrontendParams -> IO CurryProg
I/O action which reads a typed Curry program from a file (with extension
".acy") with respect to some parser options.
This I/O action is used by the standard action readCurry.
It is currently predefined only in Curry2Prolog.
Example call: (readCurryWithParseOptions progfile options)
progfile
- the program file name (without suffix ".curry")
options
- parameters passed to the front end
:: String -> FrontendParams -> IO CurryProg
I/O action which reads an untyped Curry program from a file (with extension ".uacy") with respect to some parser options. For more details see function 'readCurryWithParseOptions'
:: String -> IO CurryProg
I/O action which reads an AbstractCurry program from a file in ".acy"
format. In contrast to readCurry, this action does not parse
a source program. Thus, the argument must be the name of an existing
file (with suffix ".acy") containing an AbstractCurry program in ".acy"
format and the result is a Curry term representing this program.
It is currently predefined only in Curry2Prolog.
:: String -> CurryProg -> IO ()
Writes an AbstractCurry program into a file in ".acy" format. The first argument must be the name of the target file (with suffix ".acy").