curry-base-1.1.1: Functions for manipulating Curry programs
Copyright(c) Michael Hanus 2003
Martin Engelke 2004
Bernd Brassel 2005
LicenseBSD-3-clause
Maintainerbjp@informatik.uni-kiel.de
Stabilityexperimental
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Curry.FlatCurry.Type

Description

This module contains a definition for representing FlatCurry programs in Haskell in type Prog.

Synopsis

Representation of qualified names and (type) variables

type QName = (String, String) Source #

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 VarIndex = Int Source #

Representation of variables.

type TVarIndex = Int Source #

Type variables are represented by (TVar i) where i is a type variable index.

Data types for FlatCurry

data Visibility Source #

Visibility of various entities.

Constructors

Public

public (exported) entity

Private

private entity

Instances

Instances details
Eq Visibility Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

(==) :: Visibility -> Visibility -> Bool

(/=) :: Visibility -> Visibility -> Bool

Read Visibility Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

readsPrec :: Int -> ReadS Visibility

readList :: ReadS [Visibility]

readPrec :: ReadPrec Visibility

readListPrec :: ReadPrec [Visibility]

Show Visibility Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

showsPrec :: Int -> Visibility -> ShowS

show :: Visibility -> String

showList :: [Visibility] -> ShowS

data Prog Source #

A FlatCurry module.

A value of this data type has the form

Prog modname imports typedecls functions opdecls

where

modname
Name of this module
imports
List of modules names that are imported
typedecls
Type declarations
funcdecls
Function declarations
opdecls
Operator declarations

Constructors

Prog String [String] [TypeDecl] [FuncDecl] [OpDecl] 

Instances

Instances details
Eq Prog Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

(==) :: Prog -> Prog -> Bool

(/=) :: Prog -> Prog -> Bool

Read Prog Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

readsPrec :: Int -> ReadS Prog

readList :: ReadS [Prog]

readPrec :: ReadPrec Prog

readListPrec :: ReadPrec [Prog]

Show Prog Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

showsPrec :: Int -> Prog -> ShowS

show :: Prog -> String

showList :: [Prog] -> ShowS

data TypeDecl Source #

Declaration of algebraic data type or type synonym.

A data type declaration 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.

Instances

Instances details
Eq TypeDecl Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

(==) :: TypeDecl -> TypeDecl -> Bool

(/=) :: TypeDecl -> TypeDecl -> Bool

Read TypeDecl Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

readsPrec :: Int -> ReadS TypeDecl

readList :: ReadS [TypeDecl]

readPrec :: ReadPrec TypeDecl

readListPrec :: ReadPrec [TypeDecl]

Show TypeDecl Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

showsPrec :: Int -> TypeDecl -> ShowS

show :: TypeDecl -> String

showList :: [TypeDecl] -> ShowS

data TypeExpr Source #

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

type variable

FuncType TypeExpr TypeExpr

function type t1 -> t2

TCons QName [TypeExpr]

type constructor application

ForallType [TVarIndex] TypeExpr

forall type

Instances

Instances details
Eq TypeExpr Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

(==) :: TypeExpr -> TypeExpr -> Bool

(/=) :: TypeExpr -> TypeExpr -> Bool

Read TypeExpr Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

readsPrec :: Int -> ReadS TypeExpr

readList :: ReadS [TypeExpr]

readPrec :: ReadPrec TypeExpr

readListPrec :: ReadPrec [TypeExpr]

Show TypeExpr Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

showsPrec :: Int -> TypeExpr -> ShowS

show :: TypeExpr -> String

showList :: [TypeExpr] -> ShowS

Typeable TypeExpr Source # 
Instance details

Defined in Curry.FlatCurry.Typeable

data ConsDecl Source #

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

Constructors

Cons QName Int Visibility [TypeExpr] 

Instances

Instances details
Eq ConsDecl Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

(==) :: ConsDecl -> ConsDecl -> Bool

(/=) :: ConsDecl -> ConsDecl -> Bool

Read ConsDecl Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

readsPrec :: Int -> ReadS ConsDecl

readList :: ReadS [ConsDecl]

readPrec :: ReadPrec ConsDecl

readListPrec :: ReadPrec [ConsDecl]

Show ConsDecl Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

showsPrec :: Int -> ConsDecl -> ShowS

show :: ConsDecl -> String

showList :: [ConsDecl] -> ShowS

data OpDecl Source #

Operator declarations.

An operator declaration fix p n in Curry corresponds to the FlatCurry term (Op n fix p).

Note: the constructor definition of Op differs from the original PAKCS definition using Haskell type Integer instead of Int for representing the precedence.

Constructors

Op QName Fixity Integer 

Instances

Instances details
Eq OpDecl Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

(==) :: OpDecl -> OpDecl -> Bool

(/=) :: OpDecl -> OpDecl -> Bool

Read OpDecl Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

readsPrec :: Int -> ReadS OpDecl

readList :: ReadS [OpDecl]

readPrec :: ReadPrec OpDecl

readListPrec :: ReadPrec [OpDecl]

Show OpDecl Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

showsPrec :: Int -> OpDecl -> ShowS

show :: OpDecl -> String

showList :: [OpDecl] -> ShowS

data Fixity Source #

Fixity of an operator.

Constructors

InfixOp

non-associative infix operator

InfixlOp

left-associative infix operator

InfixrOp

right-associative infix operator

Instances

Instances details
Eq Fixity Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

(==) :: Fixity -> Fixity -> Bool

(/=) :: Fixity -> Fixity -> Bool

Read Fixity Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

readsPrec :: Int -> ReadS Fixity

readList :: ReadS [Fixity]

readPrec :: ReadPrec Fixity

readListPrec :: ReadPrec [Fixity]

Show Fixity Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

showsPrec :: Int -> Fixity -> ShowS

show :: Fixity -> String

showList :: [Fixity] -> ShowS

data FuncDecl Source #

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 QName Int Visibility TypeExpr Rule 

Instances

Instances details
Eq FuncDecl Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

(==) :: FuncDecl -> FuncDecl -> Bool

(/=) :: FuncDecl -> FuncDecl -> Bool

Read FuncDecl Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

readsPrec :: Int -> ReadS FuncDecl

readList :: ReadS [FuncDecl]

readPrec :: ReadPrec FuncDecl

readListPrec :: ReadPrec [FuncDecl]

Show FuncDecl Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

showsPrec :: Int -> FuncDecl -> ShowS

show :: FuncDecl -> String

showList :: [FuncDecl] -> ShowS

data Rule Source #

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

Constructors

Rule [VarIndex] Expr 
External String 

Instances

Instances details
Eq Rule Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

(==) :: Rule -> Rule -> Bool

(/=) :: Rule -> Rule -> Bool

Read Rule Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

readsPrec :: Int -> ReadS Rule

readList :: ReadS [Rule]

readPrec :: ReadPrec Rule

readListPrec :: ReadPrec [Rule]

Show Rule Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

showsPrec :: Int -> Rule -> ShowS

show :: Rule -> String

showList :: [Rule] -> ShowS

data Expr Source #

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])
  1. 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]))
  1. 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") []]))
  
  1. Functions with evaluation annotation choice are represented by a rule whose right-hand side is enclosed in a call to the external function Prelude.commit. Furthermore, all rules of the original definition must be represented by conditional expressions (i.e., (cond [c,e])) after pattern matching.

Example:

  m eval choice
  m [] y = y
  m x [] = x
  

is translated into (note that the conditional branches can be also wrapped with Free declarations in general):

  Rule [0,1]
    (Comb FuncCall (Prelude,"commit")
      [Or (Case Rigid (Var 0)
            [(Pattern (Prelude,"[]") []
                (Comb FuncCall (Prelude,"cond")
                      [Comb FuncCall (Prelude,"success") [],
                        Var 1]))] )
          (Case Rigid (Var 1)
            [(Pattern (Prelude,"[]") []
                (Comb FuncCall (Prelude,"cond")
                      [Comb FuncCall (Prelude,"success") [],
                        Var 0]))] )])
  

Operational meaning of (Prelude.commit e): evaluate e with local search spaces and commit to the first (Comb FuncCall (Prelude,"cond") [c,ge]) in e whose constraint c is satisfied

Constructors

Var VarIndex

Variable, represented by unique index

Lit Literal

Literal (IntegerFloatChar constant)

Comb CombType QName [Expr]

Application (f e1 ... en) of function/constructor f with n <= arity f

Free [VarIndex] Expr

Introduction of free local variables for an expression

Let [(VarIndex, Expr)] Expr

Local let-declarations

Or Expr Expr

Disjunction of two expressions (resulting from overlapping left-hand sides)

Case CaseType Expr [BranchExpr]

case expression

Typed Expr TypeExpr

typed expression

Instances

Instances details
Eq Expr Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

(==) :: Expr -> Expr -> Bool

(/=) :: Expr -> Expr -> Bool

Read Expr Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

readsPrec :: Int -> ReadS Expr

readList :: ReadS [Expr]

readPrec :: ReadPrec Expr

readListPrec :: ReadPrec [Expr]

Show Expr Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

showsPrec :: Int -> Expr -> ShowS

show :: Expr -> String

showList :: [Expr] -> ShowS

data Literal Source #

Data type for representing literals.

A literal is either an integer, a float, or a character constant.

Note: The constructor definition of Intc 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.

Constructors

Intc Integer 
Floatc Double 
Charc Char 

Instances

Instances details
Eq Literal Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

(==) :: Literal -> Literal -> Bool

(/=) :: Literal -> Literal -> Bool

Read Literal Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

readsPrec :: Int -> ReadS Literal

readList :: ReadS [Literal]

readPrec :: ReadPrec Literal

readListPrec :: ReadPrec [Literal]

Show Literal Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

showsPrec :: Int -> Literal -> ShowS

show :: Literal -> String

showList :: [Literal] -> ShowS

data CombType Source #

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

Constructors

FuncCall

a call to a function where all arguments are provided

ConsCall

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

FuncPartCall Int

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

ConsPartCall Int

a partial call to a constructor along with number of missing arguments

Instances

Instances details
Eq CombType Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

(==) :: CombType -> CombType -> Bool

(/=) :: CombType -> CombType -> Bool

Read CombType Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

readsPrec :: Int -> ReadS CombType

readList :: ReadS [CombType]

readPrec :: ReadPrec CombType

readListPrec :: ReadPrec [CombType]

Show CombType Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

showsPrec :: Int -> CombType -> ShowS

show :: CombType -> String

showList :: [CombType] -> ShowS

data CaseType Source #

Classification of case expressions, either flexible or rigid.

Constructors

Rigid 
Flex 

Instances

Instances details
Eq CaseType Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

(==) :: CaseType -> CaseType -> Bool

(/=) :: CaseType -> CaseType -> Bool

Read CaseType Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

readsPrec :: Int -> ReadS CaseType

readList :: ReadS [CaseType]

readPrec :: ReadPrec CaseType

readListPrec :: ReadPrec [CaseType]

Show CaseType Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

showsPrec :: Int -> CaseType -> ShowS

show :: CaseType -> String

showList :: [CaseType] -> ShowS

data BranchExpr Source #

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 

Instances

Instances details
Eq BranchExpr Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

(==) :: BranchExpr -> BranchExpr -> Bool

(/=) :: BranchExpr -> BranchExpr -> Bool

Read BranchExpr Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

readsPrec :: Int -> ReadS BranchExpr

readList :: ReadS [BranchExpr]

readPrec :: ReadPrec BranchExpr

readListPrec :: ReadPrec [BranchExpr]

Show BranchExpr Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

showsPrec :: Int -> BranchExpr -> ShowS

show :: BranchExpr -> String

showList :: [BranchExpr] -> ShowS

data Pattern Source #

Patterns in case expressions.

Instances

Instances details
Eq Pattern Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

(==) :: Pattern -> Pattern -> Bool

(/=) :: Pattern -> Pattern -> Bool

Read Pattern Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

readsPrec :: Int -> ReadS Pattern

readList :: ReadS [Pattern]

readPrec :: ReadPrec Pattern

readListPrec :: ReadPrec [Pattern]

Show Pattern Source # 
Instance details

Defined in Curry.FlatCurry.Type

Methods

showsPrec :: Int -> Pattern -> ShowS

show :: Pattern -> String

showList :: [Pattern] -> ShowS