Module "AbstractCurry.curry"

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:

readCurry  :: String -> IO CurryProg  deterministic 
          I/O action which parses a Curry program and returns the corresponding typed Abstract Curry program.
readUntypedCurry  :: String -> IO CurryProg  deterministic 
          I/O action which parses a Curry program and returns the corresponding untyped Abstract Curry program.
readCurryWithParseOptions  :: String -> FrontendParams -> IO CurryProg  deterministic 
          I/O action which reads a typed Curry program from a file (with extension ".acy") with respect to some parser options.
readUntypedCurryWithParseOptions  :: String -> FrontendParams -> IO CurryProg  deterministic 
          I/O action which reads an untyped Curry program from a file (with extension ".uacy") with respect to some parser options.
readAbstractCurryFile  :: String -> IO CurryProg  deterministic 
          I/O action which reads an AbstractCurry program from a file in ".acy" format.
writeAbstractCurryFile  :: String -> CurryProg -> IO ()  deterministic 
          Writes an AbstractCurry program into a file in ".acy" format.

 Imported modules:

Directory
Distribution
Prelude
ReadShowTerm

 Exported datatypes:

QName

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)


CTVarIName

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)


CVarIName

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)


CurryProg

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:

CurryProg :: String -> [String] -> [CTypeDecl] -> [CFuncDecl] -> [COpDecl] -> CurryProg


CVisibility

Constructors:

Public :: CVisibility
Private :: CVisibility


CTypeDecl

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:

CType :: (String,String) -> CVisibility -> [(Int,String)] -> [CConsDecl] -> CTypeDecl
CTypeSyn :: (String,String) -> CVisibility -> [(Int,String)] -> CTypeExpr -> CTypeDecl


CConsDecl

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

Constructors:

CCons :: (String,String) -> Int -> CVisibility -> [CTypeExpr] -> CConsDecl


CTypeExpr

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:

CTVar :: (Int,String) -> CTypeExpr
CFuncType :: CTypeExpr -> CTypeExpr -> CTypeExpr
CTCons :: (String,String) -> [CTypeExpr] -> CTypeExpr


COpDecl

Data type for operator declarations. An operator declaration "fix p n" in Curry corresponds to the AbstractCurry term (COp n fix p).

Constructors:

COp :: (String,String) -> CFixity -> Int -> COpDecl


CFixity

Constructors:

CInfixOp :: CFixity
CInfixlOp :: CFixity
CInfixrOp :: CFixity


CFuncDecl

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:

CFunc :: (String,String) -> Int -> CVisibility -> CTypeExpr -> CRules -> CFuncDecl
CmtFunc :: String -> (String,String) -> Int -> CVisibility -> CTypeExpr -> CRules -> CFuncDecl


CRules

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:

CRules :: CEvalAnnot -> [CRule] -> CRules
CExternal :: String -> CRules


CEvalAnnot

Data type for classifying evaluation annotations for functions. They can be either flexible (default), rigid, or choice.

Constructors:

CFlex :: CEvalAnnot
CRigid :: CEvalAnnot
CChoice :: CEvalAnnot


CRule

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:

CRule :: [CPattern] -> [(CExpr,CExpr)] -> [CLocalDecl] -> CRule


CLocalDecl

Data type for representing local (let/where) declarations

Constructors:

CLocalFunc :: CFuncDecl -> CLocalDecl
CLocalPat :: CPattern -> CExpr -> [CLocalDecl] -> CLocalDecl
CLocalVar :: (Int,String) -> CLocalDecl


CExpr

Data type for representing Curry expressions.

Constructors:

CVar :: (Int,String) -> CExpr
CLit :: CLiteral -> CExpr
CSymbol :: (String,String) -> CExpr
CApply :: CExpr -> CExpr -> CExpr
CLambda :: [CPattern] -> CExpr -> CExpr
CLetDecl :: [CLocalDecl] -> CExpr -> CExpr
CDoExpr :: [CStatement] -> CExpr
CListComp :: CExpr -> [CStatement] -> CExpr
CCase :: CExpr -> [CBranchExpr] -> CExpr


CStatement

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

Constructors:

CSExpr :: CExpr -> CStatement
CSPat :: CPattern -> CExpr -> CStatement
CSLet :: [CLocalDecl] -> CStatement


CPattern

Data type for representing pattern expressions.

Constructors:

CPVar :: (Int,String) -> CPattern
CPLit :: CLiteral -> CPattern
CPComb :: (String,String) -> [CPattern] -> CPattern
CPAs :: (Int,String) -> CPattern -> CPattern
CPFuncComb :: (String,String) -> [CPattern] -> CPattern


CBranchExpr

Data type for representing branches in case expressions.

Constructors:

CBranch :: CPattern -> CExpr -> CBranchExpr


CLiteral

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



 Exported functions:

readCurry :: String -> IO CurryProg  deterministic 

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.


readUntypedCurry :: String -> IO CurryProg  deterministic 

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.


readCurryWithParseOptions :: String -> FrontendParams -> IO CurryProg  deterministic 

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)

Parameters:
progfile - the program file name (without suffix ".curry")
options - parameters passed to the front end

readUntypedCurryWithParseOptions :: String -> FrontendParams -> IO CurryProg  deterministic 

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'


readAbstractCurryFile :: String -> IO CurryProg  deterministic 

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.


writeAbstractCurryFile :: String -> CurryProg -> IO ()  deterministic 

Writes an AbstractCurry program into a file in ".acy" format. The first argument must be the name of the target file (with suffix ".acy").



Generated by CurryDoc (Version 0.4.1 of June 7, 2007) at Aug 28 15:37:40 2008