Module "FlatCurry.curry"

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: August 2005


 Exported names:

Datatypes:
BranchExpr | CaseType | CombType | ConsDecl | Expr | Fixity | FuncDecl | Literal | OpDecl | Pattern | Prog | QName | Rule | TVarIndex | TypeDecl | TypeExpr | VarIndex | Visibility

Constructors:
Branch | Case | Charc | Comb | Cons | ConsCall | ConsPartCall | External | Flex | Floatc | Free | Func | FuncCall | FuncPartCall | FuncType | InfixlOp | InfixOp | InfixrOp | Intc | Let | Lit | LPattern | Op | Or | Pattern | Private | Prog | Public | Rigid | Rule | TCons | TVar | Type | TypeSyn | Var

Functions:
readFlatCurry | readFlatCurryFile | readFlatCurryInt | readFlatCurryWithParseOptions | showQNameInModule | writeFCY


 Summary of exported functions:

readFlatCurry  :: String -> IO Prog  deterministic 
          I/O action which parses a Curry program and returns the corresponding FlatCurry program.
readFlatCurryWithParseOptions  :: String -> FrontendParams -> IO Prog  deterministic 
          I/O action which reads a FlatCurry program from a file with respect to some parser options.
readFlatCurryFile  :: String -> IO Prog  deterministic 
          I/O action which reads a FlatCurry program from a file in ".fcy" format.
readFlatCurryInt  :: String -> IO Prog  deterministic 
          I/O action which returns the interface of a Curry program, i.e., a FlatCurry program containing only "Public" entities and function definitions without rules (i.e., external functions).
writeFCY  :: String -> Prog -> IO ()  deterministic 
          Writes a FlatCurry program into a file in ".fcy" format.
showQNameInModule  :: String -> (String,String) -> String  deterministic flexible+rigid
          Translates a given qualified type name into external name relative to a module.

 Imported modules:

Directory
Distribution
Prelude
ReadShowTerm

 Exported datatypes:

QName

The data type for representing qualified names. In FlatCurry 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)


TVarIndex

The data type for representing type variables. They are represented by (TVar i) where i is a type variable index.

Type synonym: TVarIndex = Int


VarIndex

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

Type synonym: VarIndex = Int


Prog

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 translation_table) where modname: name of this module, imports: list of modules names that are imported, typedecls, opdecls, functions, translation of type names and constructor/function names: see below

Constructors:

Prog :: String -> [String] -> [TypeDecl] -> [FuncDecl] -> [OpDecl] -> Prog


Visibility

Data type to specify the visibility of various entities.

Constructors:

Public :: Visibility
Private :: Visibility


TypeDecl

Data type for representing definitions of algebraic data types.
A data type definition of the form
data 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:

Type :: (String,String) -> Visibility -> [Int] -> [ConsDecl] -> TypeDecl
TypeSyn :: (String,String) -> Visibility -> [Int] -> TypeExpr -> TypeDecl


ConsDecl

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,String) -> Int -> Visibility -> [TypeExpr] -> ConsDecl


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", "Success", "()" (unit type), "(,...,)" (tuple types), "[]" (list type)

Constructors:

TVar :: Int -> TypeExpr
FuncType :: TypeExpr -> TypeExpr -> TypeExpr
TCons :: (String,String) -> [TypeExpr] -> TypeExpr


OpDecl

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,String) -> Fixity -> Int -> OpDecl


Fixity

Data types for the different choices for the fixity of an operator.

Constructors:

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


FuncDecl

Data type for representing function declarations.
A function declaration in FlatCurry is a term of the form
(Func name arity type (Rule [i_1,...,i_arity] e))
and represents the function "name" with definition
name :: type
name x_1...x_arity = e
where each i_j is the index of the variable x_j.
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:

Func :: (String,String) -> Int -> Visibility -> TypeExpr -> Rule -> FuncDecl


Rule

A rule is either a list of formal parameters together with an expression or an "External" tag.

Constructors:

Rule :: [Int] -> Expr -> Rule
External :: String -> Rule


CaseType

Data type for classifying case expressions. Case expressions can be either flexible or rigid in Curry.

Constructors:

Rigid :: CaseType
Flex :: CaseType


CombType

Data type for classifying combinations (i.e., a function/constructor applied to some arguments).

Constructors:

FuncCall :: CombType

FuncCall - a call to a function where all arguments are provided

ConsCall :: CombType

ConsCall - a call with a constructor at the top, all arguments are provided

FuncPartCall :: Int -> CombType

FuncPartCall - a partial call to a function (i.e., not all arguments are provided) where the parameter is the number of missing arguments

ConsPartCall :: Int -> CombType

ConsPartCall - a partial call to a constructor (i.e., not all arguments are provided) where the parameter is the number of missing arguments


Expr

Data type for representing expressions.
Remarks:

  1. if-then-else expressions are represented as function calls:
    (if e1 then e2 else e3)
    is represented as
    (Comb FuncCall ("Prelude","if_then_else") [e1,e2,e3])
  2. Higher-order applications are represented as calls to the (external) function "apply". For instance, the rule
    app f x = f x
    is represented as
    (Rule [0,1] (Comb FuncCall ("Prelude","apply") [Var 0, Var 1]))
  3. A conditional rule is represented as a call to an external function "cond" where the first argument is the condition (a constraint). For instance, the rule
    equal2 x | x=:=2 = success
    is represented as
    (Rule [0] (Comb FuncCall ("Prelude","cond") [Comb FuncCall ("Prelude","=:=") [Var 0, Lit (Intc 2)], Comb FuncCall ("Prelude","success") []]))

Constructors:

Var :: Int -> Expr

Var - variable (represented by unique index)

Lit :: Literal -> Expr

Lit - literal (Integer/Float/Char constant)

Comb :: CombType -> (String,String) -> [Expr] -> Expr

Comb - application (f e1 ... en) of function/constructor f with n<=arity(f)

Let :: [(Int,Expr)] -> Expr -> Expr
Free :: [Int] -> Expr -> Expr

Free - introduction of free local variables

Or :: Expr -> Expr -> Expr

Or - disjunction of two expressions (used to translate rules with overlapping left-hand sides)

Case :: CaseType -> Expr -> [BranchExpr] -> Expr

Case - case distinction (rigid or flex)


BranchExpr

Data type for representing branches in a case expression.
Branches "(m.c x1...xn) -> e" in case expressions are represented as
(Branch (Pattern (m,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:

Branch :: Pattern -> Expr -> BranchExpr


Pattern

Data type for representing patterns in case expressions.

Constructors:

Pattern :: (String,String) -> [Int] -> Pattern
LPattern :: Literal -> Pattern


Literal

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



 Exported functions:

readFlatCurry :: String -> IO Prog  deterministic 

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.


readFlatCurryWithParseOptions :: String -> FrontendParams -> IO Prog  deterministic 

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 readFlatCurry. It is currently predefined only in Curry2Prolog.

Example call:  (readFlatCurryWithParseOptions progfile options)

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

readFlatCurryFile :: String -> IO Prog  deterministic 

I/O action which reads a FlatCurry program from a file in ".fcy" format. In contrast to readFlatCurry, this action does not parse a source program. Thus, the argument must be the name of an existing file (with suffix ".fcy") containing a FlatCurry program in ".fcy" format and the result is a FlatCurry term representing this program.


readFlatCurryInt :: String -> IO Prog  deterministic 

I/O action which returns the interface of a Curry program, i.e., a FlatCurry program containing only "Public" entities and function definitions without rules (i.e., external functions). The argument is the file name without suffix ".curry" (or ".lcurry") and the result is a FlatCurry term representing the interface of this program.


writeFCY :: String -> Prog -> IO ()  deterministic 

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


showQNameInModule :: String -> (String,String) -> String  deterministic flexible+rigid

Translates a given qualified type name into external name relative to a module. Thus, names not defined in this module (except for names defined in the prelude) are prefixed with their module name.

Further infos:
  • incompletely defined


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