Copyright | Michael Hanus 2004 Martin Engelke 2005 Björn Peemöller 2015 Finn Teegen 2016 |
---|---|
License | BSD-3-clause |
Maintainer | bjp@informatik.uni-kiel.de |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
This library contains a definition for representing Curry programs
in Haskell by the type CurryProg
and I/O actions to read Curry programs
and transform them into this abstract representation as well as
write them to a file.
Note that this defines a slightly new format for AbstractCurry in comparison to the first proposal of 2003.
Synopsis
- data CurryProg = CurryProg MName [MName] (Maybe CDefaultDecl) [CClassDecl] [CInstanceDecl] [CTypeDecl] [CFuncDecl] [COpDecl]
- type MName = String
- type QName = (MName, String)
- data CVisibility
- type CTVarIName = (Int, String)
- data CDefaultDecl = CDefaultDecl [CTypeExpr]
- data CClassDecl = CClass QName CVisibility CContext CTVarIName [CFuncDecl]
- data CInstanceDecl = CInstance QName CContext CTypeExpr [CFuncDecl]
- data CTypeDecl
- data CConsDecl
- data CFieldDecl = CField QName CVisibility CTypeExpr
- type CConstraint = (QName, CTypeExpr)
- data CContext = CContext [CConstraint]
- data CTypeExpr
- data CQualTypeExpr = CQualType CContext CTypeExpr
- data COpDecl = COp QName CFixity Int
- data CFixity
- type Arity = Int
- data CFuncDecl = CFunc QName Arity CVisibility CQualTypeExpr [CRule]
- data CRhs
- = CSimpleRhs CExpr [CLocalDecl]
- | CGuardedRhs [(CExpr, CExpr)] [CLocalDecl]
- data CRule = CRule [CPattern] CRhs
- data CLocalDecl
- type CVarIName = (Int, String)
- data CExpr
- = CVar CVarIName
- | CLit CLiteral
- | CSymbol QName
- | CApply CExpr CExpr
- | CLambda [CPattern] CExpr
- | CLetDecl [CLocalDecl] CExpr
- | CDoExpr [CStatement]
- | CListComp CExpr [CStatement]
- | CCase CCaseType CExpr [(CPattern, CRhs)]
- | CTyped CExpr CQualTypeExpr
- | CRecConstr QName [CField CExpr]
- | CRecUpdate CExpr [CField CExpr]
- data CCaseType
- data CStatement
- data CPattern
- data CLiteral
- type CField a = (QName, a)
- version :: String
Documentation
A Curry module in the intermediate form. A value of this 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
[funcdecls
] Function declarations
[opdecls
] Operator precedence declarations
CurryProg MName [MName] (Maybe CDefaultDecl) [CClassDecl] [CInstanceDecl] [CTypeDecl] [CFuncDecl] [COpDecl] |
type QName = (MName, String) Source #
A qualified name. 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.
data CVisibility Source #
Data type to specify the visibility of various entities.
Instances
Eq CVisibility Source # | |
Defined in Curry.AbstractCurry.Type (==) :: CVisibility -> CVisibility -> Bool # (/=) :: CVisibility -> CVisibility -> Bool # | |
Read CVisibility Source # | |
Defined in Curry.AbstractCurry.Type readsPrec :: Int -> ReadS CVisibility # readList :: ReadS [CVisibility] # readPrec :: ReadPrec CVisibility # readListPrec :: ReadPrec [CVisibility] # | |
Show CVisibility Source # | |
Defined in Curry.AbstractCurry.Type showsPrec :: Int -> CVisibility -> ShowS # show :: CVisibility -> String # showList :: [CVisibility] -> ShowS # |
type CTVarIName = (Int, String) Source #
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).
data CDefaultDecl Source #
Default declaration.
Instances
Eq CDefaultDecl Source # | |
Defined in Curry.AbstractCurry.Type (==) :: CDefaultDecl -> CDefaultDecl -> Bool # (/=) :: CDefaultDecl -> CDefaultDecl -> Bool # | |
Read CDefaultDecl Source # | |
Defined in Curry.AbstractCurry.Type readsPrec :: Int -> ReadS CDefaultDecl # readList :: ReadS [CDefaultDecl] # | |
Show CDefaultDecl Source # | |
Defined in Curry.AbstractCurry.Type showsPrec :: Int -> CDefaultDecl -> ShowS # show :: CDefaultDecl -> String # showList :: [CDefaultDecl] -> ShowS # |
data CClassDecl Source #
Definitions of type classes.
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.
Instances
Eq CClassDecl Source # | |
Defined in Curry.AbstractCurry.Type (==) :: CClassDecl -> CClassDecl -> Bool # (/=) :: CClassDecl -> CClassDecl -> Bool # | |
Read CClassDecl Source # | |
Defined in Curry.AbstractCurry.Type readsPrec :: Int -> ReadS CClassDecl # readList :: ReadS [CClassDecl] # readPrec :: ReadPrec CClassDecl # readListPrec :: ReadPrec [CClassDecl] # | |
Show CClassDecl Source # | |
Defined in Curry.AbstractCurry.Type showsPrec :: Int -> CClassDecl -> ShowS # show :: CClassDecl -> String # showList :: [CClassDecl] -> ShowS # |
data CInstanceDecl Source #
Definitions of instances.
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).
Instances
Eq CInstanceDecl Source # | |
Defined in Curry.AbstractCurry.Type (==) :: CInstanceDecl -> CInstanceDecl -> Bool # (/=) :: CInstanceDecl -> CInstanceDecl -> Bool # | |
Read CInstanceDecl Source # | |
Defined in Curry.AbstractCurry.Type readsPrec :: Int -> ReadS CInstanceDecl # readList :: ReadS [CInstanceDecl] # | |
Show CInstanceDecl Source # | |
Defined in Curry.AbstractCurry.Type showsPrec :: Int -> CInstanceDecl -> ShowS # show :: CInstanceDecl -> String # showList :: [CInstanceDecl] -> ShowS # |
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.
CType QName CVisibility [CTVarIName] [CConsDecl] [QName] | algebraic data type |
CTypeSyn QName CVisibility [CTVarIName] CTypeExpr | type synonym |
CNewType QName CVisibility [CTVarIName] CConsDecl [QName] | renaming type, may have only exactly one type expression in the constructor declaration and no existentially type variables and no context |
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.
CCons [CTVarIName] CContext QName CVisibility [CTypeExpr] | |
CRecord [CTVarIName] CContext QName CVisibility [CFieldDecl] |
data CFieldDecl Source #
A record field declaration consists of the name of the the label, the visibility and its corresponding type.
Instances
Eq CFieldDecl Source # | |
Defined in Curry.AbstractCurry.Type (==) :: CFieldDecl -> CFieldDecl -> Bool # (/=) :: CFieldDecl -> CFieldDecl -> Bool # | |
Read CFieldDecl Source # | |
Defined in Curry.AbstractCurry.Type readsPrec :: Int -> ReadS CFieldDecl # readList :: ReadS [CFieldDecl] # readPrec :: ReadPrec CFieldDecl # readListPrec :: ReadPrec [CFieldDecl] # | |
Show CFieldDecl Source # | |
Defined in Curry.AbstractCurry.Type showsPrec :: Int -> CFieldDecl -> ShowS # show :: CFieldDecl -> String # showList :: [CFieldDecl] -> ShowS # |
type CConstraint = (QName, CTypeExpr) Source #
The type for representing a class constraint.
The type for representing a context.
Type expression. A type expression is either a type variable, a function type, a type constructor or a type application.
CTVar CTVarIName | Type variable |
CFuncType CTypeExpr CTypeExpr | Function type |
CTCons QName | Type constructor |
CTApply CTypeExpr CTypeExpr | Type application |
data CQualTypeExpr Source #
Qualified type expression.
Instances
Eq CQualTypeExpr Source # | |
Defined in Curry.AbstractCurry.Type (==) :: CQualTypeExpr -> CQualTypeExpr -> Bool # (/=) :: CQualTypeExpr -> CQualTypeExpr -> Bool # | |
Read CQualTypeExpr Source # | |
Defined in Curry.AbstractCurry.Type readsPrec :: Int -> ReadS CQualTypeExpr # readList :: ReadS [CQualTypeExpr] # | |
Show CQualTypeExpr Source # | |
Defined in Curry.AbstractCurry.Type showsPrec :: Int -> CQualTypeExpr -> ShowS # show :: CQualTypeExpr -> String # showList :: [CQualTypeExpr] -> ShowS # |
Operator precedence declaration.
An operator precedence declaration fix p n
in Curry corresponds to the
AbstractCurry term (COp n fix p)
.
Fixity declarations of infix operators
CInfixOp | non-associative infix operator |
CInfixlOp | left-associative infix operator |
CInfixrOp | right-associative infix operator |
Data type for representing function declarations.
A function declaration in FlatCurry is a term of the form
(CFunc name arity visibility type (CRules eval [CRule rule1,...,rulek]))
and represents the function name
with definition
name :: type
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.
If the list of rules is empty, the function is considered
to be externally defined.
Right-hand-side of a CRule
or an case
expression
CSimpleRhs CExpr [CLocalDecl] | |
CGuardedRhs [(CExpr, CExpr)] [CLocalDecl] |
The general form of a function 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.
data CLocalDecl Source #
Local (let/where) declarations
CLocalFunc CFuncDecl | local function declaration |
CLocalPat CPattern CRhs | local pattern declaration |
CLocalVars [CVarIName] | local free variable declarations |
Instances
Eq CLocalDecl Source # | |
Defined in Curry.AbstractCurry.Type (==) :: CLocalDecl -> CLocalDecl -> Bool # (/=) :: CLocalDecl -> CLocalDecl -> Bool # | |
Read CLocalDecl Source # | |
Defined in Curry.AbstractCurry.Type readsPrec :: Int -> ReadS CLocalDecl # readList :: ReadS [CLocalDecl] # readPrec :: ReadPrec CLocalDecl # readListPrec :: ReadPrec [CLocalDecl] # | |
Show CLocalDecl Source # | |
Defined in Curry.AbstractCurry.Type showsPrec :: Int -> CLocalDecl -> ShowS # show :: CLocalDecl -> String # showList :: [CLocalDecl] -> ShowS # |
type CVarIName = (Int, String) Source #
Variable names.
Object variables occurring in expressions are represented by (Var i)
where i
is a variable index.
Curry expressions.
CVar CVarIName | variable (unique index / name) |
CLit CLiteral | literal (IntegerFloatChar/String constant) |
CSymbol QName | a defined symbol with module and name, i.e., a function or a constructor |
CApply CExpr CExpr | application (e1 e2) |
CLambda [CPattern] CExpr | lambda abstraction |
CLetDecl [CLocalDecl] CExpr | local let declarations |
CDoExpr [CStatement] | do block |
CListComp CExpr [CStatement] | list comprehension |
CCase CCaseType CExpr [(CPattern, CRhs)] | case expression |
CTyped CExpr CQualTypeExpr | typed expression |
CRecConstr QName [CField CExpr] | record construction (extended Curry) |
CRecUpdate CExpr [CField CExpr] | record update (extended Curry) |
Type of case expressions
data CStatement Source #
Statements in do expressions and list comprehensions.
CSExpr CExpr | an expression (I/O action or boolean) |
CSPat CPattern CExpr | a pattern definition |
CSLet [CLocalDecl] | a local let declaration |
Instances
Eq CStatement Source # | |
Defined in Curry.AbstractCurry.Type (==) :: CStatement -> CStatement -> Bool # (/=) :: CStatement -> CStatement -> Bool # | |
Read CStatement Source # | |
Defined in Curry.AbstractCurry.Type readsPrec :: Int -> ReadS CStatement # readList :: ReadS [CStatement] # readPrec :: ReadPrec CStatement # readListPrec :: ReadPrec [CStatement] # | |
Show CStatement Source # | |
Defined in Curry.AbstractCurry.Type showsPrec :: Int -> CStatement -> ShowS # show :: CStatement -> String # showList :: [CStatement] -> ShowS # |
Pattern expressions.
CPVar CVarIName | pattern variable (unique index / name) |
CPLit CLiteral | literal (IntegerFloatChar constant) |
CPComb QName [CPattern] | application |
CPAs CVarIName CPattern | as-pattern (extended Curry) |
CPFuncComb QName [CPattern] | functional pattern (extended Curry) |
CPLazy CPattern | lazy pattern (extended Curry) |
CPRecord QName [CField CPattern] | record pattern (extended curry) |
Literals occurring in an expression or a pattern,
either an integer, a float, a character, or a string constant.
Note: The constructor definition of CIntc
differs from the original
PAKCS definition. It uses Haskell type Integer
instead of Int
to provide an unlimited range of integer numbers. Furthermore,
float values are represented with Haskell type Double
instead of
Float
to gain double precision.
CIntc Integer | Int literal |
CFloatc Double | Float literal |
CCharc Char | Char literal |
CStringc String | String literal |