Library to support meta-programming in Curry.
This library contains a definition for representing FlatCurry programs in Curry (type "Prog") and an I/O action to read Curry programs and transform them into this representation (function "readFlatCurry").
Author: Michael Hanus
Version: March 2001
readFlatCurry
:: String -> IO Expr
I/O action which parses a Curry program and returns the corresponding FlatCurry program. |
readFlatCurryWithParseOptions
:: String -> FrontendParams -> IO Expr
I/O action which reads a FlatCurry program from a file with respect to some parser options. |
flatCurryFileName
:: String -> String
Transforms a name of a Curry program (with or without suffix ".curry" or ".lcurry") into the name of the file containing the corresponding FlatCurry program. |
flatCurryIntName
:: String -> String
Transforms a name of a Curry program (with or without suffix ".curry" or ".lcurry") into the name of the file containing the corresponding FlatCurry program. |
readFlatCurryFile
:: String -> IO Expr
I/O action which reads a FlatCurry program from a file in ".fcy" format. |
prim_readFlatCurryFile
:: String -> IO Expr
|
splitFlatModName
:: String -> (String,String)
Splits an internal name into a pair of module name and name in local module. |
Data type for representing a Curry module in the intermediate form.
A value of this data type has the form
(Prog modname imports typedecls functions opdecls translationtable)
where modname: name of this module,
imports: list of modules names that are imported,
typedecls, opdecls, functions, translationtable: see below
Type synonym: Prog = Expr
The data type for representing type variables. They are represented by (TVar i) where i is a type variable index.
Type synonym: TVarIndex = Int
Data type for representing definitions of algebraic data types.
A data type definition of the formdata t x1...xn = ...| c t1....tkc |...
is represented by the FlatCurry term
(Type t [i1,...,in] [...(Cons c kc [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:
A constructor declaration consists of the name and arity of the constructor and a list of the argument types of the constructor.
Constructors:
Cons
:: String -> Int -> [TypeExpr] -> ConsDecl
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:
TVar
:: TVarIndex -> TypeExpr
FuncType
:: TypeExpr -> TypeExpr -> TypeExpr
TCons
:: String -> [TypeExpr] -> TypeExpr
Data type for operator declarations. An operator declaration "fix p n" in Curry corresponds to the FlatCurry term (Op n fix p).
Constructors:
Op
:: String -> Fixity -> Int -> OpDecl
Data types for the different choices for the fixity of an operator.
Constructors:
InfixOp
:: Fixity
InfixlOp
:: Fixity
InfixrOp
:: Fixity
Data types for representing object variables. Object variables occurring in expressions are represented by (Var i) where i is a variable index.
Type synonym: VarIndex = Int
Data type for representing function declarations.
A function declaration in FlatCurry is a term of the form(Func name arity type (Rule [i1,...,iarity] e))
and represents the function "name" with definition
name :: type name x1...xarity = e
where each ij is the index of the variable xj
Note: the variable indices are unique inside each function declaration and are usually numbered from 0
External functions are represented as (Func name arity type (External s)) where s is the external name associated to this function.
Thus, a function declaration consists of the name, arity, type, and rule.
Constructors:
A rule is either a list of formal parameters together with an expression or an "External" tag.
Constructors:
Data type for classifying case expressions. Case expressions can be either flexible or rigid in Curry.
Constructors:
Rigid
:: CaseType
Flex
:: CaseType
Data type for classifying combinations (i.e., a function/constructor applied to some arguments).
Constructors:
FuncCall
:: CombType
ConsCall
:: CombType
PartCall
:: CombType
Data types for representing expressions.
Constructors:
Var
:: VarIndex -> Expr
Lit
:: Literal -> Expr
Comb
:: CombType -> String -> [Expr] -> Expr
Apply
:: Expr -> Expr -> Expr
Constr
:: [VarIndex] -> Expr -> Expr
Or
:: Expr -> Expr -> Expr
Case
:: CaseType -> Expr -> [BranchExpr] -> Expr
Choice
:: Expr -> Expr
GuardedExpr
:: [VarIndex] -> Expr -> Expr -> Expr
SQ
:: Expr -> Expr
Prog
:: String -> [String] -> [TypeDecl] -> [FuncDecl] -> [OpDecl] -> [Translation] -> Expr
Data types for representing branches in a case expressions.
Branches "(c x1...xn) -> e" in case expressions are represented as(Branch (Pattern c [i1,...,in]) e)
where each ij is the index of the pattern variable xj, or as
(Branch (LPattern (Intc i)) e)
for integers as branch patterns (similarly for other literals like float or character constants).
Constructors:
Data type for representing patterns in case expressions.
Constructors:
Data type for representing literals occurring in an expression or case branch. It is either an integer, a float, or a character constant.
Constructors:
Intc
:: Int -> Literal
Floatc
:: Float -> Literal
Charc
:: Char -> Literal
Data type for translating external into internal names.
Each module contains a translation table to translate the
external names (visible to the user) into internal names (used in
the implementation). Usually, the internal names are prefixed by
the name of the module (except for the prelude). Thus, the translation
table is a list of elements of the form
(Trans name internal_name)
.
Constructors:
Trans
:: String -> String -> Translation
I/O action which parses a Curry program and returns the corresponding FlatCurry program. Thus, the argument is the file name without suffix ".curry" (or ".lcurry") and the result is a FlatCurry term representing this program. |
I/O action which reads a FlatCurry program from a file
with respect to some parser options.
This I/O action is used by the standard action
|
Transforms a name of a Curry program (with or without suffix ".curry" or ".lcurry") into the name of the file containing the corresponding FlatCurry program. |
Transforms a name of a Curry program (with or without suffix ".curry" or ".lcurry") into the name of the file containing the corresponding FlatCurry program. |
I/O action which reads a FlatCurry program from a file in ".fcy" format.
In contrast to |
|
Splits an internal name into a pair of module name and name in local module.
|