-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Functions for manipulating Curry programs
--   
--   This package serves as a foundation for Curry compilers. It defines
--   the intermediate language formats FlatCurry and ExtendedFlat.
--   Additionally, it provides functionality for the smooth integration of
--   compiler frontends and backends.
@package curry-base
@version 0.4.2


-- | This module contains a definition for representing FlatCurry programs
--   in Haskell in type <a>Prog</a>.
module Curry.FlatCurry.Type

-- | 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 QName = (String, String)

-- | Representation of variables.
type VarIndex = Int

-- | Type variables are represented by <tt>(TVar i)</tt> where <tt>i</tt>
--   is a type variable index.
type TVarIndex = Int

-- | Visibility of various entities.
data Visibility

-- | public (exported) entity
Public :: Visibility

-- | private entity
Private :: Visibility

-- | A FlatCurry module.
--   
--   A value of this data type has the form
--   
--   <pre>
--   Prog modname imports typedecls functions opdecls
--   </pre>
--   
--   where
--   
--   <ul>
--   <li><i><tt>modname</tt></i> Name of this module</li>
--   <li><i><tt>imports</tt></i> List of modules names that are
--   imported</li>
--   <li><i><tt>typedecls</tt></i> Type declarations</li>
--   <li><i><tt>funcdecls</tt></i> Function declarations</li>
--   <li><i><tt> opdecls</tt></i> Operator declarations</li>
--   </ul>
data Prog
Prog :: String -> [String] -> [TypeDecl] -> [FuncDecl] -> [OpDecl] -> Prog

-- | Declaration of algebraic data type or type synonym.
--   
--   A data type declaration of the form
--   
--   <pre>
--   data t x1...xn = ...| c t1....tkc |...
--   </pre>
--   
--   is represented by the FlatCurry term
--   
--   <pre>
--   Type t [i1,...,in] [...(Cons c kc [t1,...,tkc])...]
--   </pre>
--   
--   where each <tt>ij</tt> is the index of the type variable <tt>xj</tt>
--   
--   <i>Note:</i> 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.
data TypeDecl
Type :: QName -> Visibility -> [TVarIndex] -> [ConsDecl] -> TypeDecl
TypeSyn :: QName -> Visibility -> [TVarIndex] -> TypeExpr -> TypeDecl

-- | Type expressions.
--   
--   A type expression is either a type variable, a function type, or a
--   type constructor application.
--   
--   <i>Note:</i> the names of the predefined type constructors are
--   <tt>Int</tt>, <tt>Float</tt>, <tt>Bool</tt>, <tt>Char</tt>,
--   <tt>IO</tt>, <tt>Success</tt>, <tt>()</tt> (unit type),
--   <tt>(,...,)</tt> (tuple types), <tt>[]</tt> (list type)
data TypeExpr

-- | type variable
TVar :: TVarIndex -> TypeExpr

-- | function type <tt>t1 -&gt; t2</tt>
FuncType :: TypeExpr -> TypeExpr -> TypeExpr

-- | type constructor application
TCons :: QName -> [TypeExpr] -> TypeExpr

-- | A constructor declaration consists of the name and arity of the
--   constructor and a list of the argument types of the constructor.
data ConsDecl
Cons :: QName -> Int -> Visibility -> [TypeExpr] -> ConsDecl

-- | Operator declarations.
--   
--   An operator declaration <tt>fix p n</tt> in Curry corresponds to the
--   FlatCurry term <tt>(Op n fix p)</tt>.
--   
--   <i>Note:</i> the constructor definition of <a>Op</a> differs from the
--   original PAKCS definition using Haskell type <a>Integer</a> instead of
--   <a>Int</a> for representing the precedence.
data OpDecl
Op :: QName -> Fixity -> Int -> OpDecl

-- | Fixity of an operator.
data Fixity

-- | non-associative infix operator
InfixOp :: Fixity

-- | left-associative infix operator
InfixlOp :: Fixity

-- | right-associative infix operator
InfixrOp :: Fixity

-- | Data type for representing function declarations.
--   
--   A function declaration in FlatCurry is a term of the form
--   
--   <pre>
--   (Func name arity type (Rule [i_1,...,i_arity] e))
--   </pre>
--   
--   and represents the function "name" with definition
--   
--   <pre>
--   name :: type
--   name x_1...x_arity = e
--   </pre>
--   
--   where each <tt>i_j</tt> is the index of the variable <tt>x_j</tt>
--   
--   <i>Note:</i> The variable indices are unique inside each function
--   declaration and are usually numbered from 0.
--   
--   External functions are represented as
--   
--   <pre>
--   Func name arity type (External s)
--   </pre>
--   
--   where s is the external name associated to this function.
--   
--   Thus, a function declaration consists of the name, arity, type, and
--   rule.
data FuncDecl
Func :: QName -> Int -> Visibility -> TypeExpr -> Rule -> FuncDecl

-- | A rule is either a list of formal parameters together with an
--   expression or an <a>External</a> tag.
data Rule
Rule :: [VarIndex] -> Expr -> Rule
External :: String -> Rule

-- | Data type for representing expressions.
--   
--   Remarks:
--   
--   <ol>
--   <li>if-then-else expressions are represented as function calls:</li>
--   </ol>
--   
--   <pre>
--   (if e1 then e2 else e3)
--   </pre>
--   
--   is represented as
--   
--   <pre>
--   (Comb FuncCall (<a>Prelude</a>,"if_then_else") [e1,e2,e3])
--   </pre>
--   
--   <ol>
--   <li>Higher order applications are represented as calls to the
--   (external) function <tt>apply</tt>. For instance, the rule</li>
--   </ol>
--   
--   <pre>
--   app f x = f x
--   </pre>
--   
--   is represented as
--   
--   <pre>
--   (Rule  [0,1] (Comb FuncCall (<a>Prelude</a>,"apply") [Var 0, Var 1]))
--   </pre>
--   
--   <ol>
--   <li>A conditional rule is represented as a call to an external
--   function <tt>cond</tt> where the first argument is the condition (a
--   constraint).</li>
--   </ol>
--   
--   For instance, the rule
--   
--   <pre>
--   equal2 x | x=:=2 = success
--   </pre>
--   
--   is represented as
--   
--   <pre>
--   (Rule [0]
--       (Comb FuncCall (<a>Prelude</a>,"cond")
--             [Comb FuncCall (<a>Prelude</a>,"=:=") [Var 0, Lit (Intc 2)],
--             Comb FuncCall (<a>Prelude</a>,"success") []]))
--   
--   </pre>
--   
--   <ol>
--   <li>Functions with evaluation annotation <tt>choice</tt> are
--   represented by a rule whose right-hand side is enclosed in a call to
--   the external function <tt>Prelude.commit</tt>. Furthermore, all rules
--   of the original definition must be represented by conditional
--   expressions (i.e., (cond [c,e])) after pattern matching.</li>
--   </ol>
--   
--   Example:
--   
--   <pre>
--   m eval choice
--   m [] y = y
--   m x [] = x
--   
--   </pre>
--   
--   is translated into (note that the conditional branches can be also
--   wrapped with Free declarations in general):
--   
--   <pre>
--   Rule [0,1]
--     (Comb FuncCall (<a>Prelude</a>,"commit")
--       [Or (Case Rigid (Var 0)
--             [(Pattern (<a>Prelude</a>,"[]") []
--                 (Comb FuncCall (<a>Prelude</a>,"cond")
--                       [Comb FuncCall (<a>Prelude</a>,"success") [],
--                         Var 1]))] )
--           (Case Rigid (Var 1)
--             [(Pattern (<a>Prelude</a>,"[]") []
--                 (Comb FuncCall (<a>Prelude</a>,"cond")
--                       [Comb FuncCall (<a>Prelude</a>,"success") [],
--                         Var 0]))] )])
--   
--   </pre>
--   
--   Operational meaning of <tt>(Prelude.commit e)</tt>: evaluate
--   <tt>e</tt> with local search spaces and commit to the first <tt>(Comb
--   FuncCall (<a>Prelude</a>,"cond") [c,ge])</tt> in <tt>e</tt> whose
--   constraint <tt>c</tt> is satisfied
data Expr

-- | Variable, represented by unique index
Var :: VarIndex -> Expr

-- | Literal (Integer<i>Float</i>Char constant)
Lit :: Literal -> Expr

-- | Application <tt>(f e1 ... en)</tt> of function/constructor <tt>f</tt>
--   with <tt>n &lt;= arity f</tt>
Comb :: CombType -> QName -> [Expr] -> Expr

-- | Introduction of free local variables for an expression
Free :: [VarIndex] -> Expr -> Expr

-- | Local let-declarations
Let :: [(VarIndex, Expr)] -> Expr -> Expr

-- | Disjunction of two expressions (resulting from overlapping left-hand
--   sides)
Or :: Expr -> Expr -> Expr

-- | case expression
Case :: CaseType -> Expr -> [BranchExpr] -> Expr

-- | typed expression
Typed :: Expr -> TypeExpr -> Expr

-- | Data type for representing literals.
--   
--   A literal is either an integer, a float, or a character constant.
--   
--   <i>Note:</i> The constructor definition of <a>Intc</a> differs from
--   the original PAKCS definition. It uses Haskell type <a>Integer</a>
--   instead of <a>Int</a> to provide an unlimited range of integer
--   numbers. Furthermore, float values are represented with Haskell type
--   <a>Double</a> instead of <a>Float</a>.
data Literal
Intc :: Integer -> Literal
Floatc :: Double -> Literal
Charc :: Char -> Literal

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

-- | a call to a function where all arguments are provided
FuncCall :: CombType

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

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

-- | a partial call to a constructor along with number of missing arguments
ConsPartCall :: Int -> CombType

-- | Classification of case expressions, either flexible or rigid.
data CaseType
Rigid :: CaseType
Flex :: CaseType

-- | Branches in a case expression.
--   
--   Branches <tt>(m.c x1...xn) -&gt; e</tt> in case expressions are
--   represented as
--   
--   <pre>
--   (Branch (Pattern (m,c) [i1,...,in]) e)
--   </pre>
--   
--   where each <tt>ij</tt> is the index of the pattern variable
--   <tt>xj</tt>, or as
--   
--   <pre>
--   (Branch (LPattern (Intc i)) e)
--   </pre>
--   
--   for integers as branch patterns (similarly for other literals like
--   float or character constants).
data BranchExpr
Branch :: Pattern -> Expr -> BranchExpr

-- | Patterns in case expressions.
data Pattern
Pattern :: QName -> [VarIndex] -> Pattern
LPattern :: Literal -> Pattern
instance GHC.Show.Show Curry.FlatCurry.Type.Prog
instance GHC.Read.Read Curry.FlatCurry.Type.Prog
instance GHC.Classes.Eq Curry.FlatCurry.Type.Prog
instance GHC.Show.Show Curry.FlatCurry.Type.FuncDecl
instance GHC.Read.Read Curry.FlatCurry.Type.FuncDecl
instance GHC.Classes.Eq Curry.FlatCurry.Type.FuncDecl
instance GHC.Show.Show Curry.FlatCurry.Type.Rule
instance GHC.Read.Read Curry.FlatCurry.Type.Rule
instance GHC.Classes.Eq Curry.FlatCurry.Type.Rule
instance GHC.Show.Show Curry.FlatCurry.Type.Expr
instance GHC.Read.Read Curry.FlatCurry.Type.Expr
instance GHC.Classes.Eq Curry.FlatCurry.Type.Expr
instance GHC.Show.Show Curry.FlatCurry.Type.BranchExpr
instance GHC.Read.Read Curry.FlatCurry.Type.BranchExpr
instance GHC.Classes.Eq Curry.FlatCurry.Type.BranchExpr
instance GHC.Show.Show Curry.FlatCurry.Type.Pattern
instance GHC.Read.Read Curry.FlatCurry.Type.Pattern
instance GHC.Classes.Eq Curry.FlatCurry.Type.Pattern
instance GHC.Show.Show Curry.FlatCurry.Type.CaseType
instance GHC.Read.Read Curry.FlatCurry.Type.CaseType
instance GHC.Classes.Eq Curry.FlatCurry.Type.CaseType
instance GHC.Show.Show Curry.FlatCurry.Type.CombType
instance GHC.Read.Read Curry.FlatCurry.Type.CombType
instance GHC.Classes.Eq Curry.FlatCurry.Type.CombType
instance GHC.Show.Show Curry.FlatCurry.Type.Literal
instance GHC.Read.Read Curry.FlatCurry.Type.Literal
instance GHC.Classes.Eq Curry.FlatCurry.Type.Literal
instance GHC.Show.Show Curry.FlatCurry.Type.OpDecl
instance GHC.Read.Read Curry.FlatCurry.Type.OpDecl
instance GHC.Classes.Eq Curry.FlatCurry.Type.OpDecl
instance GHC.Show.Show Curry.FlatCurry.Type.Fixity
instance GHC.Read.Read Curry.FlatCurry.Type.Fixity
instance GHC.Classes.Eq Curry.FlatCurry.Type.Fixity
instance GHC.Show.Show Curry.FlatCurry.Type.TypeDecl
instance GHC.Read.Read Curry.FlatCurry.Type.TypeDecl
instance GHC.Classes.Eq Curry.FlatCurry.Type.TypeDecl
instance GHC.Show.Show Curry.FlatCurry.Type.ConsDecl
instance GHC.Read.Read Curry.FlatCurry.Type.ConsDecl
instance GHC.Classes.Eq Curry.FlatCurry.Type.ConsDecl
instance GHC.Show.Show Curry.FlatCurry.Type.TypeExpr
instance GHC.Read.Read Curry.FlatCurry.Type.TypeExpr
instance GHC.Classes.Eq Curry.FlatCurry.Type.TypeExpr
instance GHC.Show.Show Curry.FlatCurry.Type.Visibility
instance GHC.Read.Read Curry.FlatCurry.Type.Visibility
instance GHC.Classes.Eq Curry.FlatCurry.Type.Visibility


-- | This library provides selector functions, test and update operations
--   as well as some useful auxiliary functions for FlatCurry data terms.
--   Most of the provided functions are based on general transformation
--   functions that replace constructors with user-defined functions. For
--   recursive datatypes the transformations are defined inductively over
--   the term structure. This is quite usual for transformations on
--   FlatCurry terms, so the provided functions can be used to implement
--   specific transformations without having to explicitly state the
--   recursion. Essentially, the tedious part of such transformations -
--   descend in fairly complex term structures - is abstracted away, which
--   hopefully makes the code more clear and brief.
module Curry.FlatCurry.Goodies

-- | Update of a type's component
type Update a b = (b -> b) -> a -> a

-- | transform program
trProg :: (String -> [String] -> [TypeDecl] -> [FuncDecl] -> [OpDecl] -> a) -> Prog -> a

-- | get name from program
progName :: Prog -> String

-- | get imports from program
progImports :: Prog -> [String]

-- | get type declarations from program
progTypes :: Prog -> [TypeDecl]

-- | get functions from program
progFuncs :: Prog -> [FuncDecl]

-- | get infix operators from program
progOps :: Prog -> [OpDecl]

-- | update program
updProg :: (String -> String) -> ([String] -> [String]) -> ([TypeDecl] -> [TypeDecl]) -> ([FuncDecl] -> [FuncDecl]) -> ([OpDecl] -> [OpDecl]) -> Prog -> Prog

-- | update name of program
updProgName :: Update Prog String

-- | update imports of program
updProgImports :: Update Prog [String]

-- | update type declarations of program
updProgTypes :: Update Prog [TypeDecl]

-- | update functions of program
updProgFuncs :: Update Prog [FuncDecl]

-- | update infix operators of program
updProgOps :: Update Prog [OpDecl]

-- | get all program variables (also from patterns)
allVarsInProg :: Prog -> [VarIndex]

-- | lift transformation on expressions to program
updProgExps :: Update Prog Expr

-- | rename programs variables
rnmAllVarsInProg :: Update Prog VarIndex

-- | update all qualified names in program
updQNamesInProg :: Update Prog QName

-- | rename program (update name of and all qualified names in program)
rnmProg :: String -> Prog -> Prog

-- | transform type declaration
trType :: (QName -> Visibility -> [TVarIndex] -> [ConsDecl] -> a) -> (QName -> Visibility -> [TVarIndex] -> TypeExpr -> a) -> TypeDecl -> a

-- | get name of type declaration
typeName :: TypeDecl -> QName

-- | get visibility of type declaration
typeVisibility :: TypeDecl -> Visibility

-- | get type parameters of type declaration
typeParams :: TypeDecl -> [TVarIndex]

-- | get constructor declarations from type declaration
typeConsDecls :: TypeDecl -> [ConsDecl]

-- | get synonym of type declaration
typeSyn :: TypeDecl -> TypeExpr

-- | is type declaration a type synonym?
isTypeSyn :: TypeDecl -> Bool

-- | is type declaration declaring a regular type?
isDataTypeDecl :: TypeDecl -> Bool

-- | is type declaration declaring an external type?
isExternalType :: TypeDecl -> Bool

-- | Is the <a>TypeDecl</a> public?
isPublicType :: TypeDecl -> Bool

-- | update type declaration
updType :: (QName -> QName) -> (Visibility -> Visibility) -> ([TVarIndex] -> [TVarIndex]) -> ([ConsDecl] -> [ConsDecl]) -> (TypeExpr -> TypeExpr) -> TypeDecl -> TypeDecl

-- | update name of type declaration
updTypeName :: Update TypeDecl QName

-- | update visibility of type declaration
updTypeVisibility :: Update TypeDecl Visibility

-- | update type parameters of type declaration
updTypeParams :: Update TypeDecl [TVarIndex]

-- | update constructor declarations of type declaration
updTypeConsDecls :: Update TypeDecl [ConsDecl]

-- | update synonym of type declaration
updTypeSynonym :: Update TypeDecl TypeExpr

-- | update all qualified names in type declaration
updQNamesInType :: Update TypeDecl QName

-- | transform constructor declaration
trCons :: (QName -> Int -> Visibility -> [TypeExpr] -> a) -> ConsDecl -> a

-- | get name of constructor declaration
consName :: ConsDecl -> QName

-- | get arity of constructor declaration
consArity :: ConsDecl -> Int

-- | get visibility of constructor declaration
consVisibility :: ConsDecl -> Visibility

-- | Is the constructor declaration public?
isPublicCons :: ConsDecl -> Bool

-- | get arguments of constructor declaration
consArgs :: ConsDecl -> [TypeExpr]

-- | update constructor declaration
updCons :: (QName -> QName) -> (Int -> Int) -> (Visibility -> Visibility) -> ([TypeExpr] -> [TypeExpr]) -> ConsDecl -> ConsDecl

-- | update name of constructor declaration
updConsName :: Update ConsDecl QName

-- | update arity of constructor declaration
updConsArity :: Update ConsDecl Int

-- | update visibility of constructor declaration
updConsVisibility :: Update ConsDecl Visibility

-- | update arguments of constructor declaration
updConsArgs :: Update ConsDecl [TypeExpr]

-- | update all qualified names in constructor declaration
updQNamesInConsDecl :: Update ConsDecl QName

-- | get index from type variable
tVarIndex :: TypeExpr -> TVarIndex

-- | get domain from functional type
domain :: TypeExpr -> TypeExpr

-- | get range from functional type
range :: TypeExpr -> TypeExpr

-- | get name from constructed type
tConsName :: TypeExpr -> QName

-- | get arguments from constructed type
tConsArgs :: TypeExpr -> [TypeExpr]

-- | transform type expression
trTypeExpr :: (TVarIndex -> a) -> (QName -> [a] -> a) -> (a -> a -> a) -> TypeExpr -> a

-- | is type expression a type variable?
isTVar :: TypeExpr -> Bool

-- | is type declaration a constructed type?
isTCons :: TypeExpr -> Bool

-- | is type declaration a functional type?
isFuncType :: TypeExpr -> Bool

-- | update all type variables
updTVars :: (TVarIndex -> TypeExpr) -> TypeExpr -> TypeExpr

-- | update all type constructors
updTCons :: (QName -> [TypeExpr] -> TypeExpr) -> TypeExpr -> TypeExpr

-- | update all functional types
updFuncTypes :: (TypeExpr -> TypeExpr -> TypeExpr) -> TypeExpr -> TypeExpr

-- | get argument types from functional type
argTypes :: TypeExpr -> [TypeExpr]

-- | Compute the arity of a <a>TypeExpr</a>
typeArity :: TypeExpr -> Int

-- | get result type from (nested) functional type
resultType :: TypeExpr -> TypeExpr

-- | get indexes of all type variables
allVarsInTypeExpr :: TypeExpr -> [TVarIndex]

-- | yield the list of all contained type constructors
allTypeCons :: TypeExpr -> [QName]

-- | rename variables in type expression
rnmAllVarsInTypeExpr :: (TVarIndex -> TVarIndex) -> TypeExpr -> TypeExpr

-- | update all qualified names in type expression
updQNamesInTypeExpr :: (QName -> QName) -> TypeExpr -> TypeExpr

-- | transform operator declaration
trOp :: (QName -> Fixity -> Int -> a) -> OpDecl -> a

-- | get name from operator declaration
opName :: OpDecl -> QName

-- | get fixity of operator declaration
opFixity :: OpDecl -> Fixity

-- | get precedence of operator declaration
opPrecedence :: OpDecl -> Int

-- | update operator declaration
updOp :: (QName -> QName) -> (Fixity -> Fixity) -> (Int -> Int) -> OpDecl -> OpDecl

-- | update name of operator declaration
updOpName :: Update OpDecl QName

-- | update fixity of operator declaration
updOpFixity :: Update OpDecl Fixity

-- | update precedence of operator declaration
updOpPrecedence :: Update OpDecl Int

-- | transform function
trFunc :: (QName -> Int -> Visibility -> TypeExpr -> Rule -> a) -> FuncDecl -> a

-- | get name of function
funcName :: FuncDecl -> QName

-- | get arity of function
funcArity :: FuncDecl -> Int

-- | get visibility of function
funcVisibility :: FuncDecl -> Visibility

-- | get type of function
funcType :: FuncDecl -> TypeExpr

-- | get rule of function
funcRule :: FuncDecl -> Rule

-- | update function
updFunc :: (QName -> QName) -> (Int -> Int) -> (Visibility -> Visibility) -> (TypeExpr -> TypeExpr) -> (Rule -> Rule) -> FuncDecl -> FuncDecl

-- | update name of function
updFuncName :: Update FuncDecl QName

-- | update arity of function
updFuncArity :: Update FuncDecl Int

-- | update visibility of function
updFuncVisibility :: Update FuncDecl Visibility

-- | update type of function
updFuncType :: Update FuncDecl TypeExpr

-- | update rule of function
updFuncRule :: Update FuncDecl Rule

-- | is function public?
isPublicFunc :: FuncDecl -> Bool

-- | is function externally defined?
isExternal :: FuncDecl -> Bool

-- | get variable names in a function declaration
allVarsInFunc :: FuncDecl -> [VarIndex]

-- | get arguments of function, if not externally defined
funcArgs :: FuncDecl -> [VarIndex]

-- | get body of function, if not externally defined
funcBody :: FuncDecl -> Expr

-- | get the right-hand-sides of a <a>FuncDecl</a>
funcRHS :: FuncDecl -> [Expr]

-- | rename all variables in function
rnmAllVarsInFunc :: Update FuncDecl VarIndex

-- | update all qualified names in function
updQNamesInFunc :: Update FuncDecl QName

-- | update arguments of function, if not externally defined
updFuncArgs :: Update FuncDecl [VarIndex]

-- | update body of function, if not externally defined
updFuncBody :: Update FuncDecl Expr

-- | transform rule
trRule :: ([VarIndex] -> Expr -> a) -> (String -> a) -> Rule -> a

-- | get rules arguments if it's not external
ruleArgs :: Rule -> [VarIndex]

-- | get rules body if it's not external
ruleBody :: Rule -> Expr

-- | get rules external declaration
ruleExtDecl :: Rule -> String

-- | is rule external?
isRuleExternal :: Rule -> Bool

-- | update rule
updRule :: ([VarIndex] -> [VarIndex]) -> (Expr -> Expr) -> (String -> String) -> Rule -> Rule

-- | update rules arguments
updRuleArgs :: Update Rule [VarIndex]

-- | update rules body
updRuleBody :: Update Rule Expr

-- | update rules external declaration
updRuleExtDecl :: Update Rule String

-- | get variable names in a functions rule
allVarsInRule :: Rule -> [VarIndex]

-- | rename all variables in rule
rnmAllVarsInRule :: Update Rule VarIndex

-- | update all qualified names in rule
updQNamesInRule :: Update Rule QName

-- | transform combination type
trCombType :: a -> (Int -> a) -> a -> (Int -> a) -> CombType -> a

-- | is type of combination FuncCall?
isCombTypeFuncCall :: CombType -> Bool

-- | is type of combination FuncPartCall?
isCombTypeFuncPartCall :: CombType -> Bool

-- | is type of combination ConsCall?
isCombTypeConsCall :: CombType -> Bool

-- | is type of combination ConsPartCall?
isCombTypeConsPartCall :: CombType -> Bool

-- | get internal number of variable
varNr :: Expr -> VarIndex

-- | get literal if expression is literal expression
literal :: Expr -> Literal

-- | get combination type of a combined expression
combType :: Expr -> CombType

-- | get name of a combined expression
combName :: Expr -> QName

-- | get arguments of a combined expression
combArgs :: Expr -> [Expr]

-- | get number of missing arguments if expression is combined
missingCombArgs :: Expr -> Int

-- | get indices of varoables in let declaration
letBinds :: Expr -> [(VarIndex, Expr)]

-- | get body of let declaration
letBody :: Expr -> Expr

-- | get variable indices from declaration of free variables
freeVars :: Expr -> [VarIndex]

-- | get expression from declaration of free variables
freeExpr :: Expr -> Expr

-- | get expressions from or-expression
orExps :: Expr -> [Expr]

-- | get case-type of case expression
caseType :: Expr -> CaseType

-- | get scrutinee of case expression
caseExpr :: Expr -> Expr

-- | get branch expressions from case expression
caseBranches :: Expr -> [BranchExpr]

-- | is expression a variable?
isVar :: Expr -> Bool

-- | is expression a literal expression?
isLit :: Expr -> Bool

-- | is expression combined?
isComb :: Expr -> Bool

-- | is expression a let expression?
isLet :: Expr -> Bool

-- | is expression a declaration of free variables?
isFree :: Expr -> Bool

-- | is expression an or-expression?
isOr :: Expr -> Bool

-- | is expression a case expression?
isCase :: Expr -> Bool

-- | transform expression
trExpr :: (VarIndex -> a) -> (Literal -> a) -> (CombType -> QName -> [a] -> a) -> ([(VarIndex, a)] -> a -> a) -> ([VarIndex] -> a -> a) -> (a -> a -> a) -> (CaseType -> a -> [b] -> a) -> (Pattern -> a -> b) -> (a -> TypeExpr -> a) -> Expr -> a

-- | update all variables in given expression
updVars :: (VarIndex -> Expr) -> Expr -> Expr

-- | update all literals in given expression
updLiterals :: (Literal -> Expr) -> Expr -> Expr

-- | update all combined expressions in given expression
updCombs :: (CombType -> QName -> [Expr] -> Expr) -> Expr -> Expr

-- | update all let expressions in given expression
updLets :: ([(VarIndex, Expr)] -> Expr -> Expr) -> Expr -> Expr

-- | update all free declarations in given expression
updFrees :: ([VarIndex] -> Expr -> Expr) -> Expr -> Expr

-- | update all or expressions in given expression
updOrs :: (Expr -> Expr -> Expr) -> Expr -> Expr

-- | update all case expressions in given expression
updCases :: (CaseType -> Expr -> [BranchExpr] -> Expr) -> Expr -> Expr

-- | update all case branches in given expression
updBranches :: (Pattern -> Expr -> BranchExpr) -> Expr -> Expr

-- | update all typed expressions in given expression
updTypeds :: (Expr -> TypeExpr -> Expr) -> Expr -> Expr

-- | is expression a call of a function where all arguments are provided?
isFuncCall :: Expr -> Bool

-- | is expression a partial function call?
isFuncPartCall :: Expr -> Bool

-- | is expression a call of a constructor?
isConsCall :: Expr -> Bool

-- | is expression a partial constructor call?
isConsPartCall :: Expr -> Bool

-- | is expression fully evaluated?
isGround :: Expr -> Bool

-- | get all variables (also pattern variables) in expression
allVars :: Expr -> [VarIndex]

-- | rename all variables (also in patterns) in expression
rnmAllVars :: Update Expr VarIndex

-- | update all qualified names in expression
updQNames :: Update Expr QName

-- | transform branch expression
trBranch :: (Pattern -> Expr -> a) -> BranchExpr -> a

-- | get pattern from branch expression
branchPattern :: BranchExpr -> Pattern

-- | get expression from branch expression
branchExpr :: BranchExpr -> Expr

-- | update branch expression
updBranch :: (Pattern -> Pattern) -> (Expr -> Expr) -> BranchExpr -> BranchExpr

-- | update pattern of branch expression
updBranchPattern :: Update BranchExpr Pattern

-- | update expression of branch expression
updBranchExpr :: Update BranchExpr Expr

-- | transform pattern
trPattern :: (QName -> [VarIndex] -> a) -> (Literal -> a) -> Pattern -> a

-- | get name from constructor pattern
patCons :: Pattern -> QName

-- | get arguments from constructor pattern
patArgs :: Pattern -> [VarIndex]

-- | get literal from literal pattern
patLiteral :: Pattern -> Literal

-- | is pattern a constructor pattern?
isConsPattern :: Pattern -> Bool

-- | update pattern
updPattern :: (QName -> QName) -> ([VarIndex] -> [VarIndex]) -> (Literal -> Literal) -> Pattern -> Pattern

-- | update constructors name of pattern
updPatCons :: (QName -> QName) -> Pattern -> Pattern

-- | update arguments of constructor pattern
updPatArgs :: ([VarIndex] -> [VarIndex]) -> Pattern -> Pattern

-- | update literal of pattern
updPatLiteral :: (Literal -> Literal) -> Pattern -> Pattern

-- | build expression from pattern
patExpr :: Pattern -> Expr

-- | Is this a public <a>Visibility</a>?
isPublic :: Visibility -> Bool


-- | This module re-exports the well known pretty printing combinators from
--   Hughes and Peyton-Jones. In addition, it re-exports the type class
--   <a>Pretty</a> for pretty printing arbitrary types.
module Curry.Base.Pretty

-- | Pretty printing class. The precedence level is used in a similar way
--   as in the <a>Show</a> class. Minimal complete definition is either
--   <a>pPrintPrec</a> or <a>pPrint</a>.
class Pretty a where pPrint = pPrintPrec 0 pPrintPrec _ = pPrint pPrintList = brackets . fsep . punctuate comma . map (pPrintPrec 0)

-- | Pretty-print something in isolation.
pPrint :: Pretty a => a -> Doc

-- | Pretty-print something in a precedence context.
pPrintPrec :: Pretty a => Int -> a -> Doc

-- | Pretty-print a list.
pPrintList :: Pretty a => [a] -> Doc

-- | Pretty print a value to a <a>String</a>.
prettyShow :: Pretty a => a -> String

-- | Parenthesize an value if the boolean is true.
parenIf :: Bool -> Doc -> Doc

-- | Pretty print a <a>Maybe</a> value for the <a>Just</a> constructor only
maybePP :: (a -> Doc) -> Maybe a -> Doc

-- | A blank line.
blankLine :: Doc

-- | Above with a blank line in between. If one of the documents is empty,
--   then the other document is returned.
($++$) :: Doc -> Doc -> Doc

-- | Seperate a list of <a>Doc</a>s by a <a>blankLine</a>.
sepByBlankLine :: [Doc] -> Doc

-- | A <a>.</a> character.
dot :: Doc

-- | Precedence of function application
appPrec :: Int

-- | A left arrow <tt>&lt;-</tt>.
larrow :: Doc

-- | A right arrow <tt>-&gt;</tt>.
rarrow :: Doc

-- | A back quote <tt>`</tt>.
backQuote :: Doc

-- | A backslash @@.
backsl :: Doc

-- | A vertical bar <tt>|</tt>.
vbar :: Doc

-- | Set a document in backquotes.
bquotes :: Doc -> Doc

-- | Set a document in backquotes if the condition is <tt>True</tt>.
bquotesIf :: Bool -> Doc -> Doc

-- | Seperate a list of documents by commas
list :: [Doc] -> Doc

-- | Instance for <a>Int</a>

-- | Instance for <a>Integer</a>

-- | Instance for <a>Float</a>

-- | Instance for <a>Double</a>

-- | Instance for '()'

-- | Instance for <a>Bool</a>

-- | Instance for <a>Ordering</a>

-- | Instance for <a>Char</a>

-- | Instance for <a>Maybe</a>

-- | Instance for <a>Either</a>

-- | Instance for '[]'

-- | Instance for '(,)'

-- | Instance for '(,,)'

-- | Instance for '(,,,)'

-- | Instance for '(,,,,)'

-- | Instance for '(,,,,,)'

-- | Instance for '(,,,,,,)'

-- | Instance for '(,,,,,,,)'
instance Curry.Base.Pretty.Pretty GHC.Types.Int
instance Curry.Base.Pretty.Pretty GHC.Integer.Type.Integer
instance Curry.Base.Pretty.Pretty GHC.Types.Float
instance Curry.Base.Pretty.Pretty GHC.Types.Double
instance Curry.Base.Pretty.Pretty ()
instance Curry.Base.Pretty.Pretty GHC.Types.Bool
instance Curry.Base.Pretty.Pretty GHC.Types.Ordering
instance Curry.Base.Pretty.Pretty GHC.Types.Char
instance Curry.Base.Pretty.Pretty a => Curry.Base.Pretty.Pretty (GHC.Base.Maybe a)
instance (Curry.Base.Pretty.Pretty a, Curry.Base.Pretty.Pretty b) => Curry.Base.Pretty.Pretty (Data.Either.Either a b)
instance Curry.Base.Pretty.Pretty a => Curry.Base.Pretty.Pretty [a]
instance (Curry.Base.Pretty.Pretty a, Curry.Base.Pretty.Pretty b) => Curry.Base.Pretty.Pretty (a, b)
instance (Curry.Base.Pretty.Pretty a, Curry.Base.Pretty.Pretty b, Curry.Base.Pretty.Pretty c) => Curry.Base.Pretty.Pretty (a, b, c)
instance (Curry.Base.Pretty.Pretty a, Curry.Base.Pretty.Pretty b, Curry.Base.Pretty.Pretty c, Curry.Base.Pretty.Pretty d) => Curry.Base.Pretty.Pretty (a, b, c, d)
instance (Curry.Base.Pretty.Pretty a, Curry.Base.Pretty.Pretty b, Curry.Base.Pretty.Pretty c, Curry.Base.Pretty.Pretty d, Curry.Base.Pretty.Pretty e) => Curry.Base.Pretty.Pretty (a, b, c, d, e)
instance (Curry.Base.Pretty.Pretty a, Curry.Base.Pretty.Pretty b, Curry.Base.Pretty.Pretty c, Curry.Base.Pretty.Pretty d, Curry.Base.Pretty.Pretty e, Curry.Base.Pretty.Pretty f) => Curry.Base.Pretty.Pretty (a, b, c, d, e, f)
instance (Curry.Base.Pretty.Pretty a, Curry.Base.Pretty.Pretty b, Curry.Base.Pretty.Pretty c, Curry.Base.Pretty.Pretty d, Curry.Base.Pretty.Pretty e, Curry.Base.Pretty.Pretty f, Curry.Base.Pretty.Pretty g) => Curry.Base.Pretty.Pretty (a, b, c, d, e, f, g)
instance (Curry.Base.Pretty.Pretty a, Curry.Base.Pretty.Pretty b, Curry.Base.Pretty.Pretty c, Curry.Base.Pretty.Pretty d, Curry.Base.Pretty.Pretty e, Curry.Base.Pretty.Pretty f, Curry.Base.Pretty.Pretty g, Curry.Base.Pretty.Pretty h) => Curry.Base.Pretty.Pretty (a, b, c, d, e, f, g, h)


-- | This module implements a pretty printer for FlatCurry modules.
module Curry.FlatCurry.Pretty

-- | pretty-print a FlatCurry module
ppProg :: Prog -> Doc

-- | pretty-print the module header
ppHeader :: String -> [TypeDecl] -> [FuncDecl] -> Doc

-- | pretty-print the export list
ppExports :: [TypeDecl] -> [FuncDecl] -> Doc

-- | pretty-print an import statement
ppImport :: String -> Doc

-- | pretty-print a type declaration
ppTypeDecl :: TypeDecl -> Doc

-- | pretty-print a type expression
ppTypeExpr :: Int -> TypeExpr -> Doc

-- | pretty-print a function declaration
ppFuncDecl :: FuncDecl -> Doc

-- | pretty-print an expression
ppExpr :: Int -> Expr -> Doc

-- | pretty-print a literal
ppLiteral :: Literal -> Doc

-- | pretty-print a operator fixity declaration
ppOpDecl :: OpDecl -> Doc


-- | This module implements a data type for positions in a source file and
--   respective functions to operate on them. A source file position
--   consists of a filename, a line number, and a column number. A tab stop
--   is assumed at every eighth column.
--   
--   In addition, the type <a>SrcRef</a> identifies the path to an
--   expression in the abstract syntax tree by argument positions, which is
--   used for debugging purposes.
module Curry.Base.Position

-- | Type class for entities which have a source code <a>Position</a>
class HasPosition a where getPosition _ = NoPos setPosition _ = id

-- | Get the <a>Position</a>
getPosition :: HasPosition a => a -> Position

-- | Set the <a>Position</a>
setPosition :: HasPosition a => Position -> a -> a

-- | Source code positions
data Position

-- | Normal source code position
Position :: FilePath -> Int -> Int -> SrcRef -> Position

-- | <a>FilePath</a> of the source file
[file] :: Position -> FilePath

-- | line number, beginning at 1
[line] :: Position -> Int

-- | column number, beginning at 1
[column] :: Position -> Int

-- | reference to the abstract syntax tree
[astRef] :: Position -> SrcRef

-- | Position in the abstract syntax tree
AST :: SrcRef -> Position

-- | reference to the abstract syntax tree
[astRef] :: Position -> SrcRef

-- | no position
NoPos :: Position

-- | <tt>x @&gt; y</tt> returns <tt>x</tt> with the position obtained from
--   <tt>y</tt>
(@>) :: (HasPosition a, HasPosition b) => a -> b -> a

-- | Show a <a>Position</a> as a <a>String</a>
showPosition :: Position -> String

-- | Pretty print a <a>Position</a>
ppPosition :: Position -> Doc

-- | Pretty print the line and column of a <a>Position</a>
ppLine :: Position -> Doc

-- | Show the line and column of a <a>Position</a>
showLine :: Position -> String

-- | Absolute first position of a file
first :: FilePath -> Position

-- | Next position to the right
next :: Position -> Position

-- | Increment a position by a number of columns
incr :: Position -> Int -> Position

-- | First position after the next tabulator
tab :: Position -> Position

-- | Number of spaces for a tabulator
tabWidth :: Int

-- | First position of the next line
nl :: Position -> Position

-- | Increment the position in the abstract syntax tree
incPosition :: Position -> Int -> Position

-- | A pointer to the origin
newtype SrcRef
SrcRef :: [Int] -> SrcRef

-- | Type class for data types containing source code references
class SrcRefOf a where srcRefsOf = (: []) . srcRefOf srcRefOf = head . srcRefsOf

-- | Retrieve all <a>SrcRef</a>s
srcRefsOf :: SrcRefOf a => a -> [SrcRef]

-- | Retrieve the first <a>SrcRef</a>
srcRefOf :: SrcRefOf a => a -> SrcRef

-- | Create a source code reference
srcRef :: Int -> SrcRef

-- | The empty source code reference
noRef :: SrcRef

-- | Provide an empty <a>SrcRef</a>
mk :: (SrcRef -> a) -> a

-- | Provide no <a>SrcRef</a>s
mk' :: ([SrcRef] -> a) -> a

-- | Increment a source code reference by a given number
incSrcRef :: SrcRef -> Int -> SrcRef
instance Data.Data.Data Curry.Base.Position.Position
instance GHC.Show.Show Curry.Base.Position.Position
instance GHC.Read.Read Curry.Base.Position.Position
instance GHC.Classes.Ord Curry.Base.Position.Position
instance GHC.Classes.Eq Curry.Base.Position.Position
instance Data.Data.Data Curry.Base.Position.SrcRef
instance Curry.Base.Position.HasPosition Curry.Base.Position.Position
instance Curry.Base.Position.SrcRefOf Curry.Base.Position.Position
instance Curry.Base.Pretty.Pretty Curry.Base.Position.Position
instance GHC.Classes.Eq Curry.Base.Position.SrcRef
instance GHC.Classes.Ord Curry.Base.Position.SrcRef
instance GHC.Read.Read Curry.Base.Position.SrcRef
instance GHC.Show.Show Curry.Base.Position.SrcRef
instance Curry.Base.Pretty.Pretty Curry.Base.Position.SrcRef


-- | This module implements a data type for span information in a source
--   file and respective functions to operate on them. A source file span
--   consists of a filename, a start position and an end position.
--   
--   In addition, the type <a>SrcRef</a> identifies the path to an
--   expression in the abstract syntax tree by argument positions, which is
--   used for debugging purposes.
module Curry.Base.Span
data Span

-- | Normal source code span
Span :: FilePath -> Position -> Position -> SrcRef -> Span

-- | <a>FilePath</a> of the source file
[file] :: Span -> FilePath

-- | start position
[start] :: Span -> Position

-- | end position
[end] :: Span -> Position

-- | reference to the abstract syntax tree
[astRef] :: Span -> SrcRef

-- | Span in the abstract syntax tree
ASTSpan :: SrcRef -> Span

-- | reference to the abstract syntax tree
[astRef] :: Span -> SrcRef

-- | no span
NoSpan :: Span

-- | Show a <a>Span</a> as a <a>String</a>
showSpan :: Span -> String

-- | Pretty print a <a>Span</a>
ppSpan :: Span -> Doc

-- | Pretty print the start and end position of a <a>Span</a>
ppPositions :: Span -> Doc
fstSpan :: FilePath -> Span

-- | Compute the column of the start position of a <a>Span</a>
startCol :: Span -> Int
nextSpan :: Span -> Span
incrSpan :: Span -> Int -> Span

-- | Convert a span to a (start) position TODO: This function should be
--   removed as soon as positions are completely replaced by spans in the
--   frontend
span2Pos :: Span -> Position

-- | First position after the next tabulator
tabSpan :: Span -> Span

-- | First position of the next line
nlSpan :: Span -> Span

-- | Distance of a span, i.e. the line and column distance between start
--   and end position
type Distance = (Int, Int)

-- | Set the distance of a span, i.e. update its end position
setDistance :: Span -> Distance -> Span

-- | Move position by given distance
moveBy :: Position -> Distance -> Position
instance Data.Data.Data Curry.Base.Span.Span
instance GHC.Show.Show Curry.Base.Span.Span
instance GHC.Read.Read Curry.Base.Span.Span
instance GHC.Classes.Ord Curry.Base.Span.Span
instance GHC.Classes.Eq Curry.Base.Span.Span
instance Curry.Base.Position.SrcRefOf Curry.Base.Span.Span
instance Curry.Base.Pretty.Pretty Curry.Base.Span.Span


-- | The type message represents a compiler message with an optional source
--   code position.
module Curry.Base.Message

-- | Compiler message
data Message
Message :: Maybe Position -> Doc -> Message

-- | optional source code position
[msgPos] :: Message -> Maybe Position

-- | the message itself
[msgTxt] :: Message -> Doc

-- | Construct a <a>Message</a> without a <a>Position</a>
message :: Doc -> Message

-- | Construct a message from an entity with a <a>Position</a> and a text
posMessage :: HasPosition p => p -> Doc -> Message

-- | Show a <a>Message</a> as a warning
showWarning :: Message -> String

-- | Show a <a>Message</a> as an error
showError :: Message -> String

-- | Pretty print a <a>Message</a>
ppMessage :: Message -> Doc

-- | Pretty print a <a>Message</a> as a warning
ppWarning :: Message -> Doc

-- | Pretty print a <a>Message</a> as an error
ppError :: Message -> Doc

-- | Pretty print a list of <a>Message</a>s by vertical concatenation
ppMessages :: (Message -> Doc) -> [Message] -> Doc
instance GHC.Classes.Eq Curry.Base.Message.Message
instance GHC.Classes.Ord Curry.Base.Message.Message
instance GHC.Show.Show Curry.Base.Message.Message
instance Curry.Base.Position.HasPosition Curry.Base.Message.Message
instance Curry.Base.Pretty.Pretty Curry.Base.Message.Message


-- | The monads defined in this module provide a common way to stop
--   execution when some errors occur. They are used to integrate different
--   compiler passes smoothly.
module Curry.Base.Monad

-- | Curry compiler monad based on the <a>IO</a> monad
type CYIO a = CYT IO a

-- | Pure Curry compiler monad
type CYM a = CYT Identity a

-- | Curry compiler monad transformer
type CYT m a = WriterT [Message] (EitherT [Message] m) a

-- | Failing action with a list of messages describing the cause(s) of
--   failure.
failMessages :: Monad m => [Message] -> CYT m a

-- | Failing action with a source code position and a <a>String</a>
--   indicating the cause of failure.
failMessageAt :: Monad m => Position -> String -> CYT m a

-- | Warning with a list of messages describing the cause(s) of the
--   warnings.
warnMessages :: Monad m => [Message] -> CYT m ()

-- | Warning with a source code position and a <a>String</a> indicating the
--   cause of the warning.
warnMessageAt :: Monad m => Position -> String -> CYT m ()

-- | Lift a value into the `CYT m` monad, same as <a>return</a>.
ok :: Monad m => a -> CYT m a

-- | Run an <a>IO</a>-based Curry compiler action in the <a>IO</a> monad,
--   yielding either a list of errors or a result in case of success
--   consisting of the actual result and a (possibly empty) list of
--   warnings
runCYIO :: CYIO a -> IO (Either [Message] (a, [Message]))

-- | Run an pure Curry compiler action, yielding either a list of errors or
--   a result in case of success consisting of the actual result and a
--   (possibly empty) list of warnings
runCYM :: CYM a -> Either [Message] (a, [Message])

-- | Run an <a>IO</a>-based Curry compiler action in the <a>IO</a> monad,
--   yielding either a list of errors or a result in case of success.
runCYIOIgnWarn :: CYIO a -> IO (Either [Message] a)

-- | Run an pure Curry compiler action, yielding either a list of errors or
--   a result in case of success.
runCYMIgnWarn :: CYM a -> Either [Message] a

-- | Lift a pure action into an action based on another monad.
liftCYM :: Monad m => CYM a -> CYT m a

-- | Execute a monadic action, but ignore any warnings it issues
silent :: Monad m => CYT m a -> CYT m a


-- | This module provides the basic types and combinators to implement the
--   lexers. The combinators use continuation passing code in a monadic
--   style.
--   
--   The first argument of the continuation function is the current span,
--   and the second is the string to be parsed. The third argument is a
--   flag which signals the lexer that it is lexing the beginning of a line
--   and therefore has to check for layout tokens. The fourth argument is a
--   stack of indentations that is used to handle nested layout groups.
module Curry.Base.LexComb

-- | Type class for symbols
class (Ord s, Show s) => Symbol s

-- | Does the <a>Symbol</a> represent the end of the input?
isEOF :: Symbol s => s -> Bool

-- | Compute the distance of a <a>Symbol</a>
dist :: Symbol s => Int -> s -> Distance

-- | Type for indentations, necessary for the layout rule
type Indent = Int

-- | Type of context for representing layout grouping
type Context = [Indent]

-- | Basic lexer function
type P a = Span  Current source code span -> String  'String' to be parsed -> Bool  Flag whether the beginning of a line should be parsed, which requires layout checking -> Context  context as a stack of 'Indent's -> CYM a

-- | Pure Curry compiler monad
type CYM a = CYT Identity a

-- | success continuation
type SuccessP s a = Span -> s -> P a

-- | failure continuation
type FailP a = Span -> String -> P a

-- | A CPS lexer
type Lexer s a = SuccessP s a -> FailP a -> P a

-- | Apply a lexer on a <a>String</a> to lex the content. The second
--   parameter requires a <a>FilePath</a> to use in the <a>Span</a>
parse :: P a -> FilePath -> String -> CYM a

-- | Apply a lexer
applyLexer :: Symbol s => Lexer s [(Span, s)] -> P [(Span, s)]

-- | Lift a value into the lexer type
returnP :: a -> P a

-- | Apply the first lexer and then apply the second one, based on the
--   result of the first lexer.
thenP :: P a -> (a -> P b) -> P b
infixl 1 `thenP`

-- | Apply the first lexer and then apply the second one, ignoring the
--   first result.
thenP_ :: P a -> P b -> P b
infixl 1 `thenP_`

-- | Fail to lex on a <a>Span</a>, given an error message
failP :: Span -> String -> P a

-- | Warn on a <a>Span</a>, given a warning message
warnP :: Span -> String -> P a -> P a

-- | Apply a pure function to the lexers result
liftP :: (a -> b) -> P a -> P b

-- | Lift a lexer into the <a>P</a> monad, returning the lexer when
--   evaluated.
closeP0 :: P a -> P (P a)

-- | Lift a lexer-generating function into the <a>P</a> monad, returning
--   the function when evaluated.
closeP1 :: (a -> P b) -> P (a -> P b)

-- | Push an <a>Indent</a> to the context, increasing the levels of
--   indentation
pushContext :: Indent -> P a -> P a

-- | Pop an <a>Indent</a> from the context, decreasing the levels of
--   indentation
popContext :: P a -> P a

-- | Convert a String into a signed intergral using a given base
convertSignedIntegral :: Num a => a -> String -> a

-- | Convert a mantissa, a fraction part and an exponent into a signed
--   floating value
convertSignedFloating :: Fractional a => String -> String -> Int -> a

-- | Convert a String into an unsigned intergral using a given base
convertIntegral :: Num a => a -> String -> a

-- | Convert a mantissa, a fraction part and an exponent into an unsigned
--   floating value
convertFloating :: Fractional a => String -> String -> Int -> a


module Curry.Syntax.Lexer

-- | Data type for curry lexer tokens
data Token
Token :: Category -> Attributes -> Token

-- | Category of curry tokens
data Category
CharTok :: Category
IntTok :: Category
FloatTok :: Category
StringTok :: Category
Id :: Category
QId :: Category
Sym :: Category
QSym :: Category
LeftParen :: Category
RightParen :: Category
Semicolon :: Category
LeftBrace :: Category
RightBrace :: Category
LeftBracket :: Category
RightBracket :: Category
Comma :: Category
Underscore :: Category
Backquote :: Category
VSemicolon :: Category
VRightBrace :: Category
KW_case :: Category
KW_data :: Category
KW_do :: Category
KW_else :: Category
KW_external :: Category
KW_fcase :: Category
KW_foreign :: Category
KW_free :: Category
KW_if :: Category
KW_import :: Category
KW_in :: Category
KW_infix :: Category
KW_infixl :: Category
KW_infixr :: Category
KW_let :: Category
KW_module :: Category
KW_newtype :: Category
KW_of :: Category
KW_then :: Category
KW_type :: Category
KW_where :: Category
At :: Category
Colon :: Category
DotDot :: Category
DoubleColon :: Category
Equals :: Category
Backslash :: Category
Bar :: Category
LeftArrow :: Category
RightArrow :: Category
Tilde :: Category
Id_as :: Category
Id_ccall :: Category
Id_forall :: Category
Id_hiding :: Category
Id_interface :: Category
Id_primitive :: Category
Id_qualified :: Category
SymDot :: Category
SymMinus :: Category
SymMinusDot :: Category
PragmaLanguage :: Category
PragmaOptions :: Category
PragmaHiding :: Category
PragmaEnd :: Category
LineComment :: Category
NestedComment :: Category
EOF :: Category

-- | Attributes associated to a token
data Attributes
NoAttributes :: Attributes
CharAttributes :: Char -> String -> Attributes
[cval] :: Attributes -> Char
[original] :: Attributes -> String
IntAttributes :: Integer -> String -> Attributes
[ival] :: Attributes -> Integer
[original] :: Attributes -> String
FloatAttributes :: Double -> String -> Attributes
[fval] :: Attributes -> Double
[original] :: Attributes -> String
StringAttributes :: String -> String -> Attributes
[sval] :: Attributes -> String
[original] :: Attributes -> String
IdentAttributes :: [String] -> String -> Attributes
[modulVal] :: Attributes -> [String]
[sval] :: Attributes -> String
OptionsAttributes :: Maybe String -> String -> Attributes
[toolVal] :: Attributes -> Maybe String
[toolArgs] :: Attributes -> String

-- | Lex source code
lexSource :: FilePath -> String -> CYM [(Span, Token)]

-- | CPS-Lexer for Curry
lexer :: Lexer Token a

-- | CPS-Lexer for Curry which also lexes comments. This lexer is useful
--   for documentation tools.
fullLexer :: Lexer Token a
instance GHC.Classes.Ord Curry.Syntax.Lexer.Category
instance GHC.Classes.Eq Curry.Syntax.Lexer.Category
instance GHC.Classes.Eq Curry.Syntax.Lexer.Token
instance GHC.Classes.Ord Curry.Syntax.Lexer.Token
instance Curry.Base.LexComb.Symbol Curry.Syntax.Lexer.Token
instance GHC.Show.Show Curry.Syntax.Lexer.Attributes
instance GHC.Show.Show Curry.Syntax.Lexer.Token


-- | The parsing combinators implemented in this module are based on the
--   LL(1) parsing combinators developed by Swierstra and Duponcheel. They
--   have been adapted to using continuation passing style in order to work
--   with the lexing combinators described in the previous section. In
--   addition, the facilities for error correction are omitted in this
--   implementation.
--   
--   The two functions <tt>applyParser</tt> and <a>prefixParser</a> use the
--   specified parser for parsing a string. When <tt>applyParser</tt> is
--   used, an error is reported if the parser does not consume the whole
--   string, whereas <a>prefixParser</a> discards the rest of the input
--   string in this case.
module Curry.Base.LLParseComb

-- | CPS-Parser type
data Parser a s b

-- | Apply a parser and lexer to a <a>String</a>, whereas the
--   <a>FilePath</a> is used to identify the origin of the <a>String</a> in
--   case of parsing errors.
fullParser :: Symbol s => Parser a s a -> Lexer s a -> FilePath -> String -> CYM a

-- | Apply a parser and lexer to parse the beginning of a <a>String</a>.
--   The <a>FilePath</a> is used to identify the origin of the
--   <a>String</a> in case of parsing errors.
prefixParser :: Symbol s => Parser a s a -> Lexer s a -> FilePath -> String -> CYM a

-- | Return the current position without consuming the input
position :: Parser a s Position

-- | Always succeeding parser
succeed :: b -> Parser a s b

-- | Always failing parser with a given message
failure :: String -> Parser a s b

-- | Create a parser accepting the given <a>Symbol</a>
symbol :: s -> Parser a s s

-- | Behave like the given parser, but use the given <a>String</a> as the
--   error message if the parser fails
(<?>) :: Symbol s => Parser a s b -> String -> Parser a s b
infixl 2 <?>

-- | Deterministic choice between two parsers. The appropriate parser is
--   chosen based on the next <a>Symbol</a>
(<|>) :: Symbol s => Parser a s b -> Parser a s b -> Parser a s b
infixl 3 <|>

-- | Non-deterministic choice between two parsers.
--   
--   The other parsing combinators require that the grammar being parsed is
--   LL(1). In some cases it may be difficult or even impossible to
--   transform a grammar into LL(1) form. As a remedy, we include a
--   non-deterministic version of the choice combinator in addition to the
--   deterministic combinator adapted from the paper. For every symbol from
--   the intersection of the parser's first sets, the combinator
--   '(<a>|?</a>)' applies both parsing functions to the input stream and
--   uses that one which processes the longer prefix of the input stream
--   irrespective of whether it succeeds or fails. If both functions
--   recognize the same prefix, we choose the one that succeeds and report
--   an ambiguous parse error if both succeed.
(<|?>) :: Symbol s => Parser a s b -> Parser a s b -> Parser a s b
infixl 3 <|?>

-- | Sequential application.
(<*>) :: Applicative f => forall a b. f (a -> b) -> f a -> f b

-- | Restrict the first parser by the first <a>Symbol</a>s of the second
(<\>) :: Symbol s => Parser a s b -> Parser a s c -> Parser a s b
infixl 5 <\>

-- | Restrict a parser by a list of first <a>Symbol</a>s
(<\\>) :: Symbol s => Parser a s b -> [s] -> Parser a s b
infixl 5 <\\>

-- | An infix synonym for <a>fmap</a>.
--   
--   The name of this operator is an allusion to <tt>$</tt>. Note the
--   similarities between their types:
--   
--   <pre>
--    ($)  ::              (a -&gt; b) -&gt;   a -&gt;   b
--   (&lt;$&gt;) :: Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
--   </pre>
--   
--   Whereas <tt>$</tt> is function application, <a>&lt;$&gt;</a> is
--   function application lifted over a <a>Functor</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Convert from a <tt><tt>Maybe</tt> <tt>Int</tt></tt> to a
--   <tt><tt>Maybe</tt> <tt>String</tt></tt> using <tt>show</tt>:
--   
--   <pre>
--   &gt;&gt;&gt; show &lt;$&gt; Nothing
--   Nothing
--   
--   &gt;&gt;&gt; show &lt;$&gt; Just 3
--   Just "3"
--   </pre>
--   
--   Convert from an <tt><tt>Either</tt> <tt>Int</tt> <tt>Int</tt></tt> to
--   an <tt><tt>Either</tt> <tt>Int</tt></tt> <tt>String</tt> using
--   <tt>show</tt>:
--   
--   <pre>
--   &gt;&gt;&gt; show &lt;$&gt; Left 17
--   Left 17
--   
--   &gt;&gt;&gt; show &lt;$&gt; Right 17
--   Right "17"
--   </pre>
--   
--   Double each element of a list:
--   
--   <pre>
--   &gt;&gt;&gt; (*2) &lt;$&gt; [1,2,3]
--   [2,4,6]
--   </pre>
--   
--   Apply <tt>even</tt> to the second element of a pair:
--   
--   <pre>
--   &gt;&gt;&gt; even &lt;$&gt; (2,2)
--   (2,True)
--   </pre>
(<$>) :: Functor f => (a -> b) -> f a -> f b
infixl 4 <$>

-- | Replace the result of the parser with the first argument
(<$->) :: Symbol s => a -> Parser b s c -> Parser b s a
infixl 4 <$->

-- | Apply two parsers in sequence, but return only the result of the first
--   parser
(<*->) :: Symbol s => Parser a s b -> Parser a s c -> Parser a s b
infixl 4 <*->

-- | Apply two parsers in sequence, but return only the result of the
--   second parser
(<-*>) :: Symbol s => Parser a s b -> Parser a s c -> Parser a s c
infixl 4 <-*>

-- | Apply the parsers in sequence and apply the result function of the
--   second parse to the result of the first
(<**>) :: Symbol s => Parser a s b -> Parser a s (b -> c) -> Parser a s c
infixl 4 <**>

-- | Same as (<a>**</a>), but only applies the function if the second
--   parser succeeded.
(<??>) :: Symbol s => Parser a s b -> Parser a s (b -> b) -> Parser a s b
infixl 4 <??>

-- | Flipped function composition on parsers
(<.>) :: Symbol s => Parser a s (b -> c) -> Parser a s (c -> d) -> Parser a s (b -> d)
infixl 4 <.>

-- | Try the first parser, but return the second argument if it didn't
--   succeed
opt :: Symbol s => Parser a s b -> b -> Parser a s b
infixl 2 `opt`

-- | Choose the first succeeding parser from a non-empty list of parsers
choice :: Symbol s => [Parser a s b] -> Parser a s b

-- | Try to apply a given parser and return a boolean value if the parser
--   succeeded.
flag :: Symbol s => Parser a s b -> Parser a s Bool

-- | Try to apply a parser but forget if it succeeded
optional :: Symbol s => Parser a s b -> Parser a s ()

-- | Try to apply a parser and return its result in a <a>Maybe</a> type
option :: Symbol s => Parser a s b -> Parser a s (Maybe b)

-- | Repeatedly apply a parser for 0 or more occurences
many :: Symbol s => Parser a s b -> Parser a s [b]

-- | Repeatedly apply a parser for 1 or more occurences
many1 :: Symbol s => Parser a s b -> Parser a s [b]

-- | Parse a list with is separated by a seperator
sepBy :: Symbol s => Parser a s b -> Parser a s c -> Parser a s [b]

-- | Parse a non-empty list with is separated by a seperator
sepBy1 :: Symbol s => Parser a s b -> Parser a s c -> Parser a s [b]

-- | <tt>chainr p op x</tt> parses zero or more occurrences of <tt>p</tt>,
--   separated by <tt>op</tt>. Returns a value produced by a *right*
--   associative application of all functions returned by op. If there are
--   no occurrences of <tt>p</tt>, <tt>x</tt> is returned.
chainr :: Symbol s => Parser a s b -> Parser a s (b -> b -> b) -> b -> Parser a s b

-- | Like <a>chainr</a>, but parses one or more occurrences of p.
chainr1 :: Symbol s => Parser a s b -> Parser a s (b -> b -> b) -> Parser a s b

-- | <tt>chainr p op x</tt> parses zero or more occurrences of <tt>p</tt>,
--   separated by <tt>op</tt>. Returns a value produced by a *left*
--   associative application of all functions returned by op. If there are
--   no occurrences of <tt>p</tt>, <tt>x</tt> is returned.
chainl :: Symbol s => Parser a s b -> Parser a s (b -> b -> b) -> b -> Parser a s b

-- | Like <a>chainl</a>, but parses one or more occurrences of p.
chainl1 :: Symbol s => Parser a s b -> Parser a s (b -> b -> b) -> Parser a s b

-- | Parse an expression between an opening and a closing part.
between :: Symbol s => Parser a s b -> Parser a s c -> Parser a s b -> Parser a s c

-- | Parse one of the given operators
ops :: Symbol s => [(s, b)] -> Parser a s b

-- | Add a new scope for layout
layoutOn :: Symbol s => Parser a s b

-- | Disable layout-awareness for the following
layoutOff :: Symbol s => Parser a s b

-- | End the current layout scope (or re-enable layout-awareness if it is
--   currently disabled
layoutEnd :: Symbol s => Parser a s b
instance Curry.Base.LexComb.Symbol s => GHC.Base.Functor (Curry.Base.LLParseComb.Parser a s)
instance Curry.Base.LexComb.Symbol s => GHC.Base.Applicative (Curry.Base.LLParseComb.Parser a s)
instance GHC.Show.Show s => GHC.Show.Show (Curry.Base.LLParseComb.Parser a s b)


-- | This module provides the implementation of identifiers and some
--   utility functions for identifiers.
--   
--   Identifiers comprise the name of the denoted entity and an <i>id</i>,
--   which can be used for renaming identifiers, e.g., in order to resolve
--   name conflicts between identifiers from different scopes. An
--   identifier with an <i>id</i> <tt>0</tt> is considered as not being
--   renamed and, hence, its <i>id</i> will not be shown.
--   
--   Qualified identifiers may optionally be prefixed by a module name.
module Curry.Base.Ident

-- | Module identifier
data ModuleIdent
ModuleIdent :: Position -> [String] -> ModuleIdent

-- | source code <a>Position</a>
[midPosition] :: ModuleIdent -> Position

-- | hierarchical idenfiers
[midQualifiers] :: ModuleIdent -> [String]

-- | Construct a <a>ModuleIdent</a> from a list of <a>String</a>s forming
--   the the hierarchical module name.
mkMIdent :: [String] -> ModuleIdent

-- | Retrieve the hierarchical name of a module
moduleName :: ModuleIdent -> String

-- | Show the name of an <a>ModuleIdent</a> escaped by ticks
escModuleName :: ModuleIdent -> String

-- | Resemble the hierarchical module name from a <a>String</a> by
--   splitting the <a>String</a> at inner dots.
--   
--   <i>Note:</i> This function does not check the <a>String</a> to be a
--   valid module identifier, use isValidModuleName for this purpose.
fromModuleName :: String -> ModuleIdent

-- | Check whether a <a>String</a> is a valid module name.
--   
--   Valid module names must satisfy the following conditions:
--   
--   <ul>
--   <li>The name must not be empty</li>
--   <li>The name must consist of one or more single identifiers, seperated
--   by dots</li>
--   <li>Each single identifier must be non-empty, start with a letter and
--   consist of letter, digits, single quotes or underscores only</li>
--   </ul>
isValidModuleName :: String -> Bool

-- | Add a source code <a>Position</a> to a <a>ModuleIdent</a>
addPositionModuleIdent :: Position -> ModuleIdent -> ModuleIdent

-- | Simple identifier
data Ident
Ident :: Position -> String -> Integer -> Ident

-- | Source code <a>Position</a>
[idPosition] :: Ident -> Position

-- | Name of the identifier
[idName] :: Ident -> String

-- | Unique number of the identifier
[idUnique] :: Ident -> Integer

-- | Construct an <a>Ident</a> from a <a>String</a>
mkIdent :: String -> Ident

-- | Show function for an <a>Ident</a>
showIdent :: Ident -> String

-- | Show the name of an <a>Ident</a> escaped by ticks
escName :: Ident -> String

-- | Infinite list of different <a>Ident</a>s
identSupply :: [Ident]

-- | Global scope for renaming
globalScope :: Integer

-- | Has the identifier global scope?
hasGlobalScope :: Ident -> Bool

-- | Is the <a>Ident</a> renamed?
isRenamed :: Ident -> Bool

-- | Rename an <a>Ident</a> by changing its unique number
renameIdent :: Ident -> Integer -> Ident

-- | Revert the renaming of an <a>Ident</a> by resetting its unique number
unRenameIdent :: Ident -> Ident

-- | Change the name of an <a>Ident</a> using a renaming function
updIdentName :: (String -> String) -> Ident -> Ident

-- | Add a <a>Position</a> to an <a>Ident</a>
addPositionIdent :: Position -> Ident -> Ident

-- | Add a <a>SrcRef</a> to an <a>Ident</a>
addRefId :: SrcRef -> Ident -> Ident

-- | Check whether an <a>Ident</a> identifies an infix operation
isInfixOp :: Ident -> Bool

-- | Qualified identifier
data QualIdent
QualIdent :: Maybe ModuleIdent -> Ident -> QualIdent

-- | optional module identifier
[qidModule] :: QualIdent -> Maybe ModuleIdent

-- | identifier itself
[qidIdent] :: QualIdent -> Ident

-- | show function for qualified identifiers
qualName :: QualIdent -> String

-- | Show the name of an <a>QualIdent</a> escaped by ticks
escQualName :: QualIdent -> String

-- | Retrieve the <a>Position</a> of a <a>QualIdent</a>
qidPosition :: QualIdent -> Position

-- | Check whether an <a>QualIdent</a> identifies an infix operation
isQInfixOp :: QualIdent -> Bool

-- | Convert an <a>Ident</a> to a <a>QualIdent</a>
qualify :: Ident -> QualIdent

-- | Convert an <a>Ident</a> to a <a>QualIdent</a> with a given
--   <a>ModuleIdent</a>
qualifyWith :: ModuleIdent -> Ident -> QualIdent

-- | Convert an <a>QualIdent</a> to a new <a>QualIdent</a> with a given
--   <a>ModuleIdent</a>. If the original <a>QualIdent</a> already contains
--   an <a>ModuleIdent</a> it remains unchanged.
qualQualify :: ModuleIdent -> QualIdent -> QualIdent

-- | Qualify an <a>Ident</a> with the <a>ModuleIdent</a> of the given
--   <a>QualIdent</a>, if present.
qualifyLike :: QualIdent -> Ident -> QualIdent

-- | Check whether a <a>QualIdent</a> contains a <a>ModuleIdent</a>
isQualified :: QualIdent -> Bool

-- | Remove the qualification of an <a>QualIdent</a>
unqualify :: QualIdent -> Ident

-- | Remove the qualification with a specific <a>ModuleIdent</a>. If the
--   original <a>QualIdent</a> has no <a>ModuleIdent</a> or a different
--   one, it remains unchanged.
qualUnqualify :: ModuleIdent -> QualIdent -> QualIdent

-- | Extract the <a>Ident</a> of an <a>QualIdent</a> if it is local to the
--   <a>ModuleIdent</a>, i.e. if the <a>Ident</a> is either unqualified or
--   qualified with the given <a>ModuleIdent</a>.
localIdent :: ModuleIdent -> QualIdent -> Maybe Ident

-- | Check whether the given <a>QualIdent</a> is local to the given
--   <a>ModuleIdent</a>.
isLocalIdent :: ModuleIdent -> QualIdent -> Bool

-- | Update a <a>QualIdent</a> by applying functions to its components
updQualIdent :: (ModuleIdent -> ModuleIdent) -> (Ident -> Ident) -> QualIdent -> QualIdent

-- | Add a <a>SrcRef</a> to a <a>QualIdent</a>
addRef :: SrcRef -> QualIdent -> QualIdent

-- | <a>ModuleIdent</a> for the empty module
emptyMIdent :: ModuleIdent

-- | <a>ModuleIdent</a> for the main module
mainMIdent :: ModuleIdent

-- | <a>ModuleIdent</a> for the Prelude
preludeMIdent :: ModuleIdent

-- | <a>Ident</a> for the type/value unit ('()')
unitId :: Ident

-- | <a>Ident</a> for the type <a>Bool</a>
boolId :: Ident

-- | <a>Ident</a> for the type <a>Char</a>
charId :: Ident

-- | <a>Ident</a> for the type <a>Int</a>
intId :: Ident

-- | <a>Ident</a> for the type <a>Float</a>
floatId :: Ident

-- | <a>Ident</a> for the type '[]'
listId :: Ident

-- | <a>Ident</a> for the type <a>IO</a>
ioId :: Ident

-- | <a>Ident</a> for the type <tt>Success</tt>
successId :: Ident

-- | <a>Ident</a> for the value <a>True</a>
trueId :: Ident

-- | <a>Ident</a> for the value <a>False</a>
falseId :: Ident

-- | <a>Ident</a> for the value '[]'
nilId :: Ident

-- | <a>Ident</a> for the function <tt>:</tt>
consId :: Ident

-- | Construct an <a>Ident</a> for an n-ary tuple where n &gt; 1
tupleId :: Int -> Ident

-- | Check whether an <a>Ident</a> is an identifier for an tuple type
isTupleId :: Ident -> Bool

-- | Compute the arity of a tuple identifier
tupleArity :: Ident -> Int

-- | <a>Ident</a> for the main function
mainId :: Ident

-- | <a>Ident</a> for the minus function
minusId :: Ident

-- | <a>Ident</a> for the minus function for Floats
fminusId :: Ident

-- | <a>Ident</a> for anonymous variable
anonId :: Ident

-- | Check whether an <a>Ident</a> represents an anonymous identifier
--   (<a>anonId</a>)
isAnonId :: Ident -> Bool

-- | <a>QualIdent</a> for the type/value unit ('()')
qUnitId :: QualIdent

-- | <a>QualIdent</a> for the type <a>Bool</a>
qBoolId :: QualIdent

-- | <a>QualIdent</a> for the type <a>Char</a>
qCharId :: QualIdent

-- | <a>QualIdent</a> for the type <a>Int</a>
qIntId :: QualIdent

-- | <a>QualIdent</a> for the type <a>Float</a>
qFloatId :: QualIdent

-- | <a>QualIdent</a> for the type '[]'
qListId :: QualIdent

-- | <a>QualIdent</a> for the type <a>IO</a>
qIOId :: QualIdent

-- | <a>QualIdent</a> for the type <tt>Success</tt>
qSuccessId :: QualIdent

-- | <a>QualIdent</a> for the constructor <a>True</a>
qTrueId :: QualIdent

-- | <a>QualIdent</a> for the constructor <a>False</a>
qFalseId :: QualIdent

-- | <a>QualIdent</a> for the constructor '[]'
qNilId :: QualIdent

-- | <a>QualIdent</a> for the constructor <tt>:</tt>
qConsId :: QualIdent

-- | <a>QualIdent</a> for the type of n-ary tuples
qTupleId :: Int -> QualIdent

-- | Check whether an <a>QualIdent</a> is an identifier for an tuple type
isQTupleId :: QualIdent -> Bool

-- | Compute the arity of an qualified tuple identifier
qTupleArity :: QualIdent -> Int

-- | Construct an <a>Ident</a> for a functional pattern
fpSelectorId :: Int -> Ident

-- | Check whether an <a>Ident</a> is an identifier for a functional
--   pattern
isFpSelectorId :: Ident -> Bool

-- | Check whether an <a>QualIdent</a> is an identifier for a function
--   pattern
isQualFpSelectorId :: QualIdent -> Bool

-- | Construct an <a>Ident</a> for a record selection pattern
recSelectorId :: QualIdent -> Ident -> Ident

-- | Construct a <a>QualIdent</a> for a record selection pattern
qualRecSelectorId :: ModuleIdent -> QualIdent -> Ident -> QualIdent

-- | Construct an <a>Ident</a> for a record update pattern
recUpdateId :: QualIdent -> Ident -> Ident

-- | Construct a <a>QualIdent</a> for a record update pattern
qualRecUpdateId :: ModuleIdent -> QualIdent -> Ident -> QualIdent

-- | Annotation for record identifiers
recordExt :: String

-- | Construct an <a>Ident</a> for a record
recordExtId :: Ident -> Ident

-- | Check whether an <a>Ident</a> is an identifier for a record
isRecordExtId :: Ident -> Bool

-- | Retrieve the <a>Ident</a> from a record identifier
fromRecordExtId :: Ident -> Ident

-- | Annotation for record label identifiers
labelExt :: String

-- | Construct an <a>Ident</a> for a record label
labelExtId :: Ident -> Ident

-- | Check whether an <a>Ident</a> is an identifier for a record label
isLabelExtId :: Ident -> Bool

-- | Retrieve the <a>Ident</a> from a record label identifier
fromLabelExtId :: Ident -> Ident

-- | Rename an <a>Ident</a> for a record label
renameLabel :: Ident -> Ident

-- | Construct an <a>Ident</a> for a record label
mkLabelIdent :: String -> Ident
instance Data.Data.Data Curry.Base.Ident.QualIdent
instance GHC.Show.Show Curry.Base.Ident.QualIdent
instance GHC.Read.Read Curry.Base.Ident.QualIdent
instance GHC.Classes.Ord Curry.Base.Ident.QualIdent
instance GHC.Classes.Eq Curry.Base.Ident.QualIdent
instance Data.Data.Data Curry.Base.Ident.Ident
instance GHC.Show.Show Curry.Base.Ident.Ident
instance GHC.Read.Read Curry.Base.Ident.Ident
instance Data.Data.Data Curry.Base.Ident.ModuleIdent
instance GHC.Show.Show Curry.Base.Ident.ModuleIdent
instance GHC.Read.Read Curry.Base.Ident.ModuleIdent
instance GHC.Classes.Eq Curry.Base.Ident.ModuleIdent
instance GHC.Classes.Ord Curry.Base.Ident.ModuleIdent
instance Curry.Base.Position.HasPosition Curry.Base.Ident.ModuleIdent
instance Curry.Base.Pretty.Pretty Curry.Base.Ident.ModuleIdent
instance Curry.Base.Position.SrcRefOf Curry.Base.Ident.ModuleIdent
instance GHC.Classes.Eq Curry.Base.Ident.Ident
instance GHC.Classes.Ord Curry.Base.Ident.Ident
instance Curry.Base.Position.HasPosition Curry.Base.Ident.Ident
instance Curry.Base.Pretty.Pretty Curry.Base.Ident.Ident
instance Curry.Base.Position.SrcRefOf Curry.Base.Ident.Ident
instance Curry.Base.Position.HasPosition Curry.Base.Ident.QualIdent
instance Curry.Base.Pretty.Pretty Curry.Base.Ident.QualIdent
instance Curry.Base.Position.SrcRefOf Curry.Base.Ident.QualIdent


-- | The functions in this module were collected from several compiler
--   modules in order to provide a unique accessing point for this
--   functionality.
module Curry.Files.Filenames

-- | File and directory names are values of type <a>String</a>, whose
--   precise meaning is operating system dependent. Files can be opened,
--   yielding a handle which can then be used to operate on the contents of
--   that file.
type FilePath = String

-- | Get the base name, without an extension or path.
--   
--   <pre>
--   takeBaseName "/directory/file.ext" == "file"
--   takeBaseName "file/test.txt" == "test"
--   takeBaseName "dave.ext" == "dave"
--   takeBaseName "" == ""
--   takeBaseName "test" == "test"
--   takeBaseName (addTrailingPathSeparator x) == ""
--   takeBaseName "file/file.tar.gz" == "file.tar"
--   </pre>
takeBaseName :: FilePath -> String

-- | Remove last extension, and the "." preceding it.
--   
--   <pre>
--   dropExtension "/directory/path.ext" == "/directory/path"
--   dropExtension x == fst (splitExtension x)
--   </pre>
dropExtension :: FilePath -> FilePath

-- | Get the extension of a file, returns <tt>""</tt> for no extension,
--   <tt>.ext</tt> otherwise.
--   
--   <pre>
--   takeExtension "/directory/path.ext" == ".ext"
--   takeExtension x == snd (splitExtension x)
--   Valid x =&gt; takeExtension (addExtension x "ext") == ".ext"
--   Valid x =&gt; takeExtension (replaceExtension x "ext") == ".ext"
--   </pre>
takeExtension :: FilePath -> String

-- | Get the file name.
--   
--   <pre>
--   takeFileName "/directory/file.ext" == "file.ext"
--   takeFileName "test/" == ""
--   takeFileName x `isSuffixOf` x
--   takeFileName x == snd (splitFileName x)
--   Valid x =&gt; takeFileName (replaceFileName x "fred") == "fred"
--   Valid x =&gt; takeFileName (x &lt;/&gt; "fred") == "fred"
--   Valid x =&gt; isRelative (takeFileName x)
--   </pre>
takeFileName :: FilePath -> FilePath

-- | Create a <a>FilePath</a> from a <a>ModuleIdent</a> using the
--   hierarchical module system
moduleNameToFile :: ModuleIdent -> FilePath

-- | Extract the <a>ModuleIdent</a> from a <a>FilePath</a>
fileNameToModule :: FilePath -> ModuleIdent

-- | Split a <a>FilePath</a> into a prefix directory part and those part
--   that corresponds to the <a>ModuleIdent</a>. This is especially useful
--   for hierarchically module names.
splitModuleFileName :: ModuleIdent -> FilePath -> (FilePath, FilePath)

-- | Checks whether a <a>String</a> represents a <a>FilePath</a> to a Curry
--   module
isCurryFilePath :: String -> Bool

-- | The standard hidden subdirectory for curry files
currySubdir :: String

-- | Does the given <a>FilePath</a> contain the <a>currySubdir</a> as its
--   last directory component?
hasCurrySubdir :: FilePath -> Bool

-- | Add the <a>currySubdir</a> to the given <a>FilePath</a> if the flag is
--   <a>True</a> and the path does not already contain it, otherwise leave
--   the path untouched.
addCurrySubdir :: Bool -> FilePath -> FilePath

-- | Add the <a>currySubdir</a> to the given <a>FilePath</a> if the flag is
--   <a>True</a> and the path does not already contain it, otherwise leave
--   the path untouched.
addCurrySubdirModule :: Bool -> ModuleIdent -> FilePath -> FilePath

-- | Ensure that the <a>currySubdir</a> is the last component of the
--   directory structure of the given <a>FilePath</a>. If the
--   <a>FilePath</a> already contains the sub-directory, it remains
--   unchanged.
ensureCurrySubdir :: FilePath -> FilePath

-- | Filename extension for non-literate curry files
curryExt :: String

-- | Filename extension for literate curry files
lcurryExt :: String

-- | Filename extension for curry interface files
icurryExt :: String

-- | Filename extension for flat-curry files
flatExt :: String

-- | Filename extension for extended-flat-curry files
extFlatExt :: String

-- | Filename extension for extended-flat-curry interface files
flatIntExt :: String

-- | Filename extension for abstract-curry files
acyExt :: String

-- | Filename extension for untyped-abstract-curry files
uacyExt :: String

-- | Filename extension for curry source representation files
sourceRepExt :: String

-- | Filename extension for curry source files.
--   
--   <i>Note:</i> The order of the extensions defines the order in which
--   source files should be searched for, i.e. given a module name
--   <tt>M</tt>, the search order should be the following:
--   
--   <ol>
--   <li><pre>M.curry</pre></li>
--   <li><pre>M.lcurry</pre></li>
--   </ol>
sourceExts :: [String]

-- | Filename extension for curry module files TODO: Is the order correct?
moduleExts :: [String]

-- | Compute the filename of the interface file for a source file
interfName :: FilePath -> FilePath

-- | Compute the filename of the flat curry file for a source file
flatName :: FilePath -> FilePath

-- | Compute the filename of the extended flat curry file for a source file
extFlatName :: FilePath -> FilePath

-- | Compute the filename of the flat curry interface file for a source
--   file
flatIntName :: FilePath -> FilePath

-- | Compute the filename of the abstract curry file for a source file
acyName :: FilePath -> FilePath

-- | Compute the filename of the untyped abstract curry file for a source
--   file
uacyName :: FilePath -> FilePath

-- | Compute the filename of the source representation file for a source
--   file
sourceRepName :: FilePath -> FilePath

-- | Compute the filename of the tokens file for a source file
tokensName :: FilePath -> FilePath

-- | Compute the filename of the HTML file for a source file
htmlName :: ModuleIdent -> String


-- | Since version 0.7 of the language report, Curry accepts literate
--   source programs. In a literate source, all program lines must begin
--   with a greater sign in the first column. All other lines are assumed
--   to be documentation. In order to avoid some common errors with
--   literate programs, Curry requires at least one program line to be
--   present in the file. In addition, every block of program code must be
--   preceded by a blank line and followed by a blank line.
module Curry.Files.Unlit

-- | Check whether a <a>FilePath</a> represents a literate Curry module
isLiterate :: FilePath -> Bool

-- | Process a curry program into error messages (if any) and the
--   corresponding non-literate program.
unlit :: FilePath -> String -> CYM String


module Curry.Files.PathUtils

-- | Search in the given list of paths for the given <a>FilePath</a> and
--   eventually return the file name of the found file.
--   
--   <ul>
--   <li>If the file name already contains a directory, then the paths to
--   search in are ignored.</li>
--   <li>If the file name has no extension, then a source file extension is
--   assumed.</li>
--   </ul>
lookupCurryFile :: [FilePath] -> FilePath -> IO (Maybe FilePath)

-- | Search for a given curry module in the given source file and library
--   paths. Note that the current directory is always searched first.
--   Returns the path of the found file.
lookupCurryModule :: [FilePath] -> [FilePath] -> ModuleIdent -> IO (Maybe FilePath)

-- | Search for an interface file in the import search path using the
--   interface extension <a>icurryExt</a>. Note that the current directory
--   is always searched first.
lookupCurryInterface :: [FilePath] -> ModuleIdent -> IO (Maybe FilePath)

-- | Search in the given directories for the file with the specified file
--   extensions and eventually return the <a>FilePath</a> of the file.
lookupFile :: [FilePath] -> [String] -> FilePath -> IO (Maybe FilePath)

-- | Get the modification time of a file, if existent
getModuleModTime :: FilePath -> IO (Maybe UTCTime)

-- | Write the content to a file in the given directory.
writeModule :: FilePath -> String -> IO ()

-- | Read the specified module and returns either 'Just String' if reading
--   was successful or <a>Nothing</a> otherwise.
readModule :: FilePath -> IO (Maybe String)

-- | Add the given version string to the file content
addVersion :: String -> String -> String

-- | Check a source file for the given version string
checkVersion :: String -> String -> Either String String


-- | This is the extended version of FlatCurry, containing part calls for
--   constructors, source references and typed expressions.
module Curry.ExtendedFlat.Type

-- | A pointer to the origin
data SrcRef

-- | 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.
--   
--   The additional information about source references and types should be
--   invisible for the normal usage of <a>QName</a>.
data QName
QName :: Maybe SrcRef -> Maybe TypeExpr -> String -> String -> QName

-- | source reference
[srcRef] :: QName -> Maybe SrcRef

-- | type of the identifier
[typeofQName] :: QName -> Maybe TypeExpr

-- | module name
[modName] :: QName -> String

-- | identifier name
[localName] :: QName -> String

-- | Select the module name and the identifier from a qualified name
qnOf :: QName -> (String, String)

-- | Construct a qualified name from a module name and an identifier
mkQName :: (String, String) -> QName

-- | Representation of variables. The additional information should be
--   invisible for the normal usage.
data VarIndex
VarIndex :: Maybe TypeExpr -> Int -> VarIndex

-- | type of the variable
[typeofVar] :: VarIndex -> Maybe TypeExpr

-- | index of the variable
[idxOf] :: VarIndex -> Int

-- | Construct a <a>VarIndex</a>
mkIdx :: Int -> VarIndex

-- | Increase the index of a variable by the given number
incVarIndex :: VarIndex -> Int -> VarIndex

-- | Visibility of various entities.
data Visibility

-- | public (exported) entity
Public :: Visibility

-- | private entity
Private :: Visibility

-- | A FlatCurry module.
--   
--   A value of this data type has the form
--   
--   <pre>
--   Prog modname imports typedecls functions opdecls
--   </pre>
--   
--   where
--   
--   <ul>
--   <li><i><tt>modname</tt></i> Name of this module</li>
--   <li><i><tt>imports</tt></i> List of modules names that are
--   imported</li>
--   <li><i><tt>typedecls</tt></i> Type declarations</li>
--   <li><i><tt>funcdecls</tt></i> Function declarations</li>
--   <li><i><tt> opdecls</tt></i> Operator declarations</li>
--   </ul>
data Prog
Prog :: String -> [String] -> [TypeDecl] -> [FuncDecl] -> [OpDecl] -> Prog

-- | Declaration of algebraic data type or type synonym.
--   
--   A data type declaration of the form
--   
--   <pre>
--   data t x1...xn = ...| c t1....tkc |...
--   </pre>
--   
--   is represented by the FlatCurry term
--   
--   <pre>
--   Type t [i1,...,in] [...(Cons c kc [t1,...,tkc])...]
--   </pre>
--   
--   where each <tt>ij</tt> is the index of the type variable <tt>xj</tt>
--   
--   <i>Note:</i> 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.
data TypeDecl
Type :: QName -> Visibility -> [TVarIndex] -> [ConsDecl] -> TypeDecl
TypeSyn :: QName -> Visibility -> [TVarIndex] -> TypeExpr -> TypeDecl

-- | Type expressions.
--   
--   A type expression is either a type variable, a function type, or a
--   type constructor application.
--   
--   <i>Note:</i> the names of the predefined type constructors are
--   <tt>Int</tt>, <tt>Float</tt>, <tt>Bool</tt>, <tt>Char</tt>,
--   <tt>IO</tt>, <tt>Success</tt>, <tt>()</tt> (unit type),
--   <tt>(,...,)</tt> (tuple types), <tt>[]</tt> (list type)
data TypeExpr

-- | type variable
TVar :: !TVarIndex -> TypeExpr

-- | function type <tt>t1 -&gt; t2</tt>
FuncType :: TypeExpr -> TypeExpr -> TypeExpr

-- | type constructor application
TCons :: QName -> [TypeExpr] -> TypeExpr

-- | Type variables are represented by <tt>(TVar i)</tt> where <tt>i</tt>
--   is a type variable index.
type TVarIndex = Int

-- | A constructor declaration consists of the name and arity of the
--   constructor and a list of the argument types of the constructor.
data ConsDecl
Cons :: QName -> Int -> Visibility -> [TypeExpr] -> ConsDecl

-- | Operator declarations.
--   
--   An operator declaration <tt>fix p n</tt> in Curry corresponds to the
--   FlatCurry term <tt>(Op n fix p)</tt>.
--   
--   <i>Note:</i> the constructor definition of <a>Op</a> differs from the
--   original PAKCS definition using Haskell type <a>Integer</a> instead of
--   <a>Int</a> for representing the precedence.
data OpDecl
Op :: QName -> Fixity -> Integer -> OpDecl

-- | Fixity of an operator.
data Fixity

-- | non-associative infix operator
InfixOp :: Fixity

-- | left-associative infix operator
InfixlOp :: Fixity

-- | right-associative infix operator
InfixrOp :: Fixity

-- | Data type for representing function declarations.
--   
--   A function declaration in FlatCurry is a term of the form
--   
--   <pre>
--   (Func name arity type (Rule [i_1,...,i_arity] e))
--   </pre>
--   
--   and represents the function "name" with definition
--   
--   <pre>
--   name :: type
--   name x_1...x_arity = e
--   </pre>
--   
--   where each <tt>i_j</tt> is the index of the variable <tt>x_j</tt>
--   
--   <i>Note:</i> The variable indices are unique inside each function
--   declaration and are usually numbered from 0.
--   
--   External functions are represented as
--   
--   <pre>
--   Func name arity type (External s)
--   </pre>
--   
--   where s is the external name associated to this function.
--   
--   Thus, a function declaration consists of the name, arity, type, and
--   rule.
data FuncDecl
Func :: QName -> Int -> Visibility -> TypeExpr -> Rule -> FuncDecl

-- | A rule is either a list of formal parameters together with an
--   expression or an <a>External</a> tag.
data Rule
Rule :: [VarIndex] -> Expr -> Rule
External :: String -> Rule

-- | Data type for representing expressions.
--   
--   Remarks:
--   
--   <ol>
--   <li>if-then-else expressions are represented as function calls:</li>
--   </ol>
--   
--   <pre>
--   (if e1 then e2 else e3)
--   </pre>
--   
--   is represented as
--   
--   <pre>
--   (Comb FuncCall (<a>Prelude</a>,"if_then_else") [e1,e2,e3])
--   </pre>
--   
--   <ol>
--   <li>Higher order applications are represented as calls to the
--   (external) function <tt>apply</tt>. For instance, the rule</li>
--   </ol>
--   
--   <pre>
--   app f x = f x
--   </pre>
--   
--   is represented as
--   
--   <pre>
--   (Rule  [0,1] (Comb FuncCall (<a>Prelude</a>,"apply") [Var 0, Var 1]))
--   </pre>
--   
--   <ol>
--   <li>A conditional rule is represented as a call to an external
--   function <tt>cond</tt> where the first argument is the condition (a
--   constraint).</li>
--   </ol>
--   
--   For instance, the rule
--   
--   <pre>
--   equal2 x | x=:=2 = success
--   </pre>
--   
--   is represented as
--   
--   <pre>
--   (Rule [0]
--       (Comb FuncCall (<a>Prelude</a>,"cond")
--             [Comb FuncCall (<a>Prelude</a>,"=:=") [Var 0, Lit (Intc 2)],
--             Comb FuncCall (<a>Prelude</a>,"success") []]))
--   
--   </pre>
--   
--   <ol>
--   <li>Functions with evaluation annotation <tt>choice</tt> are
--   represented by a rule whose right-hand side is enclosed in a call to
--   the external function <tt>Prelude.commit</tt>. Furthermore, all rules
--   of the original definition must be represented by conditional
--   expressions (i.e., (cond [c,e])) after pattern matching.</li>
--   </ol>
--   
--   Example:
--   
--   <pre>
--   m eval choice
--   m [] y = y
--   m x [] = x
--   
--   </pre>
--   
--   is translated into (note that the conditional branches can be also
--   wrapped with Free declarations in general):
--   
--   <pre>
--   Rule [0,1]
--     (Comb FuncCall (<a>Prelude</a>,"commit")
--       [Or (Case Rigid (Var 0)
--             [(Pattern (<a>Prelude</a>,"[]") []
--                 (Comb FuncCall (<a>Prelude</a>,"cond")
--                       [Comb FuncCall (<a>Prelude</a>,"success") [],
--                         Var 1]))] )
--           (Case Rigid (Var 1)
--             [(Pattern (<a>Prelude</a>,"[]") []
--                 (Comb FuncCall (<a>Prelude</a>,"cond")
--                       [Comb FuncCall (<a>Prelude</a>,"success") [],
--                         Var 0]))] )])
--   
--   </pre>
--   
--   Operational meaning of <tt>(Prelude.commit e)</tt>: evaluate
--   <tt>e</tt> with local search spaces and commit to the first <tt>(Comb
--   FuncCall (<a>Prelude</a>,"cond") [c,ge])</tt> in <tt>e</tt> whose
--   constraint <tt>c</tt> is satisfied
data Expr

-- | Variable, represented by unique index
Var :: VarIndex -> Expr

-- | Literal (Integer<i>Float</i>Char constant)
Lit :: Literal -> Expr

-- | Application <tt>(f e1 ... en)</tt> of function/constructor <tt>f</tt>
--   with <tt>n &lt;= arity f</tt>
Comb :: CombType -> QName -> [Expr] -> Expr

-- | Introduction of free local variables for an expression
Free :: [VarIndex] -> Expr -> Expr

-- | Local let-declarations
Let :: [(VarIndex, Expr)] -> Expr -> Expr

-- | Disjunction of two expressions (resulting from overlapping left-hand
--   sides)
Or :: Expr -> Expr -> Expr

-- | case expression
Case :: SrcRef -> CaseType -> Expr -> [BranchExpr] -> Expr

-- | typed expression
Typed :: Expr -> TypeExpr -> Expr

-- | Data type for representing literals.
--   
--   A literal is either an integer, a float, or a character constant.
--   
--   <i>Note:</i> The constructor definition of <a>Intc</a> differs from
--   the original PAKCS definition. It uses Haskell type <a>Integer</a>
--   instead of <a>Int</a> to provide an unlimited range of integer
--   numbers. Furthermore, float values are represented with Haskell type
--   <a>Double</a> instead of <a>Float</a>.
data Literal

-- | <a>Integer</a> literal
Intc :: SrcRef -> Integer -> Literal

-- | <a>Float</a> literal
Floatc :: SrcRef -> Double -> Literal

-- | <a>Char</a> literal
Charc :: SrcRef -> Char -> Literal

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

-- | a call to a function where all arguments are provided
FuncCall :: CombType

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

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

-- | a partial call to a constructor along with number of missing arguments
ConsPartCall :: Int -> CombType

-- | Classification of case expressions, either flexible or rigid.
data CaseType

-- | rigid case expression
Rigid :: CaseType

-- | flexible case expression
Flex :: CaseType

-- | Branches in a case expression.
--   
--   Branches <tt>(m.c x1...xn) -&gt; e</tt> in case expressions are
--   represented as
--   
--   <pre>
--   (Branch (Pattern (m,c) [i1,...,in]) e)
--   </pre>
--   
--   where each <tt>ij</tt> is the index of the pattern variable
--   <tt>xj</tt>, or as
--   
--   <pre>
--   (Branch (LPattern (Intc i)) e)
--   </pre>
--   
--   for integers as branch patterns (similarly for other literals like
--   float or character constants).
data BranchExpr
Branch :: Pattern -> Expr -> BranchExpr

-- | Patterns in case expressions.
data Pattern

-- | constructor pattern
Pattern :: QName -> [VarIndex] -> Pattern

-- | literal pattern
LPattern :: Literal -> Pattern

-- | Reads an FlatCurry file (extension ".fcy") and eventually returns the
--   corresponding FlatCurry program term (type <a>Prog</a>).
readFlatCurry :: FilePath -> IO (Maybe Prog)

-- | Reads a FlatInterface file (extension ".fint") and returns the
--   corresponding term (type <a>Prog</a>) as a value of type <a>Maybe</a>.
readFlatInterface :: String -> IO (Maybe Prog)

-- | Reads an Extended FlatCurry file (extension ".efc") and eventually
--   returns the corresponding FlatCurry program term (type <a>Prog</a>).
readExtFlatCurry :: FilePath -> IO (Maybe Prog)

-- | Reads a Flat file and returns the corresponding term (type
--   <a>Prog</a>) as a value of type <a>Maybe</a>.
readFlat :: FilePath -> IO (Maybe Prog)

-- | Writes a FlatCurry program term into a file.
writeFlatCurry :: String -> Prog -> IO ()

-- | Writes a FlatCurry program term with source references into a file.
writeExtendedFlat :: String -> Prog -> IO ()
instance Data.Data.Data Curry.ExtendedFlat.Type.Prog
instance GHC.Show.Show Curry.ExtendedFlat.Type.Prog
instance GHC.Read.Read Curry.ExtendedFlat.Type.Prog
instance GHC.Classes.Eq Curry.ExtendedFlat.Type.Prog
instance Data.Data.Data Curry.ExtendedFlat.Type.FuncDecl
instance GHC.Show.Show Curry.ExtendedFlat.Type.FuncDecl
instance GHC.Read.Read Curry.ExtendedFlat.Type.FuncDecl
instance GHC.Classes.Eq Curry.ExtendedFlat.Type.FuncDecl
instance Data.Data.Data Curry.ExtendedFlat.Type.Rule
instance GHC.Show.Show Curry.ExtendedFlat.Type.Rule
instance GHC.Read.Read Curry.ExtendedFlat.Type.Rule
instance GHC.Classes.Eq Curry.ExtendedFlat.Type.Rule
instance Data.Data.Data Curry.ExtendedFlat.Type.Expr
instance GHC.Show.Show Curry.ExtendedFlat.Type.Expr
instance GHC.Read.Read Curry.ExtendedFlat.Type.Expr
instance GHC.Classes.Eq Curry.ExtendedFlat.Type.Expr
instance Data.Data.Data Curry.ExtendedFlat.Type.BranchExpr
instance GHC.Show.Show Curry.ExtendedFlat.Type.BranchExpr
instance GHC.Read.Read Curry.ExtendedFlat.Type.BranchExpr
instance GHC.Classes.Eq Curry.ExtendedFlat.Type.BranchExpr
instance Data.Data.Data Curry.ExtendedFlat.Type.Pattern
instance GHC.Show.Show Curry.ExtendedFlat.Type.Pattern
instance GHC.Read.Read Curry.ExtendedFlat.Type.Pattern
instance GHC.Classes.Eq Curry.ExtendedFlat.Type.Pattern
instance Data.Data.Data Curry.ExtendedFlat.Type.CaseType
instance GHC.Show.Show Curry.ExtendedFlat.Type.CaseType
instance GHC.Read.Read Curry.ExtendedFlat.Type.CaseType
instance GHC.Classes.Eq Curry.ExtendedFlat.Type.CaseType
instance Data.Data.Data Curry.ExtendedFlat.Type.CombType
instance GHC.Show.Show Curry.ExtendedFlat.Type.CombType
instance GHC.Read.Read Curry.ExtendedFlat.Type.CombType
instance GHC.Classes.Eq Curry.ExtendedFlat.Type.CombType
instance Data.Data.Data Curry.ExtendedFlat.Type.Literal
instance GHC.Show.Show Curry.ExtendedFlat.Type.Literal
instance GHC.Read.Read Curry.ExtendedFlat.Type.Literal
instance GHC.Classes.Eq Curry.ExtendedFlat.Type.Literal
instance Data.Data.Data Curry.ExtendedFlat.Type.OpDecl
instance GHC.Show.Show Curry.ExtendedFlat.Type.OpDecl
instance GHC.Read.Read Curry.ExtendedFlat.Type.OpDecl
instance GHC.Classes.Eq Curry.ExtendedFlat.Type.OpDecl
instance Data.Data.Data Curry.ExtendedFlat.Type.Fixity
instance GHC.Show.Show Curry.ExtendedFlat.Type.Fixity
instance GHC.Read.Read Curry.ExtendedFlat.Type.Fixity
instance GHC.Classes.Eq Curry.ExtendedFlat.Type.Fixity
instance Data.Data.Data Curry.ExtendedFlat.Type.TypeDecl
instance GHC.Show.Show Curry.ExtendedFlat.Type.TypeDecl
instance GHC.Read.Read Curry.ExtendedFlat.Type.TypeDecl
instance GHC.Classes.Eq Curry.ExtendedFlat.Type.TypeDecl
instance Data.Data.Data Curry.ExtendedFlat.Type.ConsDecl
instance GHC.Show.Show Curry.ExtendedFlat.Type.ConsDecl
instance GHC.Read.Read Curry.ExtendedFlat.Type.ConsDecl
instance GHC.Classes.Eq Curry.ExtendedFlat.Type.ConsDecl
instance Data.Data.Data Curry.ExtendedFlat.Type.VarIndex
instance Data.Data.Data Curry.ExtendedFlat.Type.QName
instance Data.Data.Data Curry.ExtendedFlat.Type.TypeExpr
instance GHC.Show.Show Curry.ExtendedFlat.Type.TypeExpr
instance GHC.Read.Read Curry.ExtendedFlat.Type.TypeExpr
instance GHC.Classes.Eq Curry.ExtendedFlat.Type.TypeExpr
instance Data.Data.Data Curry.ExtendedFlat.Type.Visibility
instance GHC.Show.Show Curry.ExtendedFlat.Type.Visibility
instance GHC.Read.Read Curry.ExtendedFlat.Type.Visibility
instance GHC.Classes.Eq Curry.ExtendedFlat.Type.Visibility
instance GHC.Read.Read Curry.ExtendedFlat.Type.QName
instance GHC.Show.Show Curry.ExtendedFlat.Type.QName
instance GHC.Classes.Eq Curry.ExtendedFlat.Type.QName
instance GHC.Classes.Ord Curry.ExtendedFlat.Type.QName
instance GHC.Read.Read Curry.ExtendedFlat.Type.VarIndex
instance GHC.Show.Show Curry.ExtendedFlat.Type.VarIndex
instance GHC.Classes.Eq Curry.ExtendedFlat.Type.VarIndex
instance GHC.Classes.Ord Curry.ExtendedFlat.Type.VarIndex
instance GHC.Num.Num Curry.ExtendedFlat.Type.VarIndex


module Curry.ExtendedFlat.CurryArithmetics

-- | Data type for curry's <a>Int</a> representation
data CurryInt

-- | negative integer
Neg :: CurryNat -> CurryInt

-- | zero
Zero :: CurryInt

-- | positive integer
Pos :: CurryNat -> CurryInt

-- | Data type for curry's representation of natural numbers
data CurryNat

-- | highest one bit
IHi :: CurryNat

-- | zero bit
O :: CurryNat -> CurryNat

-- | one bit
I :: CurryNat -> CurryNat

-- | Translate a natural number into its algebraic representation,
--   providing functions for representing the highest bit, a zero bit and a
--   one bit.
trNat :: Integral n => a -> (a -> a) -> (a -> a) -> n -> a

-- | Translate an <a>Integral</a> number into its algebraic representation,
--   providing functions for representing negative numbers, zero, positive
--   numbers, highest bit, a zero bit and a one bit.
trInt :: Integral n => (nat -> t) -> t -> (nat -> t) -> nat -> (nat -> nat) -> (nat -> nat) -> n -> t

-- | Convert an <a>Integral</a> value into its algebraic representation.
toCurryInt :: Integral a => a -> CurryInt

-- | Convert an <a>Integral</a> value into an expression constructing its
--   algebraic representation.
toIntExpression :: Integral a => a -> Expr


-- | This library provides selector functions, test and update operations
--   as well as some useful auxiliary functions for FlatCurry data terms.
--   Most of the provided functions are based on general transformation
--   functions that replace constructors with user-defined functions. For
--   recursive datatypes the transformations are defined inductively over
--   the term structure. This is quite usual for transformations on
--   FlatCurry terms, so the provided functions can be used to implement
--   specific transformations without having to explicitly state the
--   recursion. Essentially, the tedious part of such transformations -
--   descend in fairly complex term structures - is abstracted away, which
--   hopefully makes the code more clear and brief.
module Curry.ExtendedFlat.Goodies

-- | Failed transformation
failed :: String -> a

-- | Error occurred inside a function
errorIn :: String -> String -> a

-- | Update of a type's component
type Update a b = (b -> b) -> a -> a

-- | transform program
trProg :: (String -> [String] -> [TypeDecl] -> [FuncDecl] -> [OpDecl] -> a) -> Prog -> a

-- | get name from program
progName :: Prog -> String

-- | get imports from program
progImports :: Prog -> [String]

-- | get type declarations from program
progTypes :: Prog -> [TypeDecl]

-- | get functions from program
progFuncs :: Prog -> [FuncDecl]

-- | get infix operators from program
progOps :: Prog -> [OpDecl]

-- | update program
updProg :: (String -> String) -> ([String] -> [String]) -> ([TypeDecl] -> [TypeDecl]) -> ([FuncDecl] -> [FuncDecl]) -> ([OpDecl] -> [OpDecl]) -> Prog -> Prog

-- | update name of program
updProgName :: Update Prog String

-- | update imports of program
updProgImports :: Update Prog [String]

-- | update type declarations of program
updProgTypes :: Update Prog [TypeDecl]

-- | update functions of program
updProgFuncs :: Update Prog [FuncDecl]

-- | update infix operators of program
updProgOps :: Update Prog [OpDecl]

-- | get all program variables (also from patterns)
allVarsInProg :: Prog -> [VarIndex]

-- | lift transformation on expressions to program
updProgExps :: Update Prog Expr

-- | rename programs variables
rnmAllVarsInProg :: Update Prog VarIndex

-- | update all qualified names in program
updQNamesInProg :: Update Prog QName

-- | rename program (update name of and all qualified names in program)
rnmProg :: String -> Prog -> Prog

-- | transform type declaration
trType :: (QName -> Visibility -> [TVarIndex] -> [ConsDecl] -> a) -> (QName -> Visibility -> [TVarIndex] -> TypeExpr -> a) -> TypeDecl -> a

-- | get name of type declaration
typeName :: TypeDecl -> QName

-- | get visibility of type declaration
typeVisibility :: TypeDecl -> Visibility

-- | get type parameters of type declaration
typeParams :: TypeDecl -> [TVarIndex]

-- | get constructor declarations from type declaration
typeConsDecls :: TypeDecl -> [ConsDecl]

-- | get synonym of type declaration
typeSyn :: TypeDecl -> TypeExpr

-- | is type declaration a type synonym?
isTypeSyn :: TypeDecl -> Bool

-- | is type declaration declaring a regular type?
isDataTypeDecl :: TypeDecl -> Bool

-- | is type declaration declaring an external type?
isExternalType :: TypeDecl -> Bool

-- | update type declaration
updType :: (QName -> QName) -> (Visibility -> Visibility) -> ([TVarIndex] -> [TVarIndex]) -> ([ConsDecl] -> [ConsDecl]) -> (TypeExpr -> TypeExpr) -> TypeDecl -> TypeDecl

-- | update name of type declaration
updTypeName :: Update TypeDecl QName

-- | update visibility of type declaration
updTypeVisibility :: Update TypeDecl Visibility

-- | update type parameters of type declaration
updTypeParams :: Update TypeDecl [TVarIndex]

-- | update constructor declarations of type declaration
updTypeConsDecls :: Update TypeDecl [ConsDecl]

-- | update synonym of type declaration
updTypeSynonym :: Update TypeDecl TypeExpr

-- | update all qualified names in type declaration
updQNamesInType :: Update TypeDecl QName

-- | transform constructor declaration
trCons :: (QName -> Int -> Visibility -> [TypeExpr] -> a) -> ConsDecl -> a

-- | get name of constructor declaration
consName :: ConsDecl -> QName

-- | get arity of constructor declaration
consArity :: ConsDecl -> Int

-- | get visibility of constructor declaration
consVisibility :: ConsDecl -> Visibility

-- | get arguments of constructor declaration
consArgs :: ConsDecl -> [TypeExpr]

-- | update constructor declaration
updCons :: (QName -> QName) -> (Int -> Int) -> (Visibility -> Visibility) -> ([TypeExpr] -> [TypeExpr]) -> ConsDecl -> ConsDecl

-- | update name of constructor declaration
updConsName :: Update ConsDecl QName

-- | update arity of constructor declaration
updConsArity :: Update ConsDecl Int

-- | update visibility of constructor declaration
updConsVisibility :: Update ConsDecl Visibility

-- | update arguments of constructor declaration
updConsArgs :: Update ConsDecl [TypeExpr]

-- | update all qualified names in constructor declaration
updQNamesInConsDecl :: Update ConsDecl QName

-- | get index from type variable
tVarIndex :: TypeExpr -> TVarIndex

-- | get domain from functional type
domain :: TypeExpr -> TypeExpr

-- | get range from functional type
range :: TypeExpr -> TypeExpr

-- | get name from constructed type
tConsName :: TypeExpr -> QName

-- | get arguments from constructed type
tConsArgs :: TypeExpr -> [TypeExpr]

-- | transform type expression
trTypeExpr :: (TVarIndex -> a) -> (QName -> [a] -> a) -> (a -> a -> a) -> TypeExpr -> a

-- | is type expression a type variable?
isTVar :: TypeExpr -> Bool

-- | is type declaration a constructed type?
isTCons :: TypeExpr -> Bool

-- | is type declaration a functional type?
isFuncType :: TypeExpr -> Bool

-- | update all type variables
updTVars :: (TVarIndex -> TypeExpr) -> TypeExpr -> TypeExpr

-- | update all type constructors
updTCons :: (QName -> [TypeExpr] -> TypeExpr) -> TypeExpr -> TypeExpr

-- | update all functional types
updFuncTypes :: (TypeExpr -> TypeExpr -> TypeExpr) -> TypeExpr -> TypeExpr

-- | get argument types from functional type
argTypes :: TypeExpr -> [TypeExpr]

-- | get result type from (nested) functional type
resultType :: TypeExpr -> TypeExpr

-- | get indexes of all type variables
allVarsInTypeExpr :: TypeExpr -> [TVarIndex]

-- | rename variables in type expression
rnmAllVarsInTypeExpr :: (TVarIndex -> TVarIndex) -> TypeExpr -> TypeExpr

-- | update all qualified names in type expression
updQNamesInTypeExpr :: (QName -> QName) -> TypeExpr -> TypeExpr

-- | transform operator declaration
trOp :: (QName -> Fixity -> Integer -> a) -> OpDecl -> a

-- | get name from operator declaration
opName :: OpDecl -> QName

-- | get fixity of operator declaration
opFixity :: OpDecl -> Fixity

-- | get precedence of operator declaration
opPrecedence :: OpDecl -> Integer

-- | update operator declaration
updOp :: (QName -> QName) -> (Fixity -> Fixity) -> (Integer -> Integer) -> OpDecl -> OpDecl

-- | update name of operator declaration
updOpName :: Update OpDecl QName

-- | update fixity of operator declaration
updOpFixity :: Update OpDecl Fixity

-- | update precedence of operator declaration
updOpPrecedence :: Update OpDecl Integer

-- | transform function
trFunc :: (QName -> Int -> Visibility -> TypeExpr -> Rule -> a) -> FuncDecl -> a

-- | get name of function
funcName :: FuncDecl -> QName

-- | get arity of function
funcArity :: FuncDecl -> Int

-- | get visibility of function
funcVisibility :: FuncDecl -> Visibility

-- | get type of function
funcType :: FuncDecl -> TypeExpr

-- | get rule of function
funcRule :: FuncDecl -> Rule

-- | update function
updFunc :: (QName -> QName) -> (Int -> Int) -> (Visibility -> Visibility) -> (TypeExpr -> TypeExpr) -> (Rule -> Rule) -> FuncDecl -> FuncDecl

-- | update name of function
updFuncName :: Update FuncDecl QName

-- | update arity of function
updFuncArity :: Update FuncDecl Int

-- | update visibility of function
updFuncVisibility :: Update FuncDecl Visibility

-- | update type of function
updFuncType :: Update FuncDecl TypeExpr

-- | update rule of function
updFuncRule :: Update FuncDecl Rule

-- | is function externally defined?
isExternal :: FuncDecl -> Bool

-- | get variable names in a function declaration
allVarsInFunc :: FuncDecl -> [VarIndex]

-- | get arguments of function, if not externally defined
funcArgs :: FuncDecl -> [VarIndex]

-- | get body of function, if not externally defined
funcBody :: FuncDecl -> Expr

-- | get the right-hand-sides of a <a>FuncDecl</a>
funcRHS :: FuncDecl -> [Expr]

-- | rename all variables in function
rnmAllVarsInFunc :: Update FuncDecl VarIndex

-- | update all qualified names in function
updQNamesInFunc :: Update FuncDecl QName

-- | update arguments of function, if not externally defined
updFuncArgs :: Update FuncDecl [VarIndex]

-- | update body of function, if not externally defined
updFuncBody :: Update FuncDecl Expr

-- | transform rule
trRule :: ([VarIndex] -> Expr -> a) -> (String -> a) -> Rule -> a

-- | get rules arguments if it's not external
ruleArgs :: Rule -> [VarIndex]

-- | get rules body if it's not external
ruleBody :: Rule -> Expr

-- | get rules external declaration
ruleExtDecl :: Rule -> String

-- | is rule external?
isRuleExternal :: Rule -> Bool

-- | update rule
updRule :: ([VarIndex] -> [VarIndex]) -> (Expr -> Expr) -> (String -> String) -> Rule -> Rule

-- | update rules arguments
updRuleArgs :: Update Rule [VarIndex]

-- | update rules body
updRuleBody :: Update Rule Expr

-- | update rules external declaration
updRuleExtDecl :: Update Rule String

-- | get variable names in a functions rule
allVarsInRule :: Rule -> [VarIndex]

-- | rename all variables in rule
rnmAllVarsInRule :: Update Rule VarIndex

-- | update all qualified names in rule
updQNamesInRule :: Update Rule QName

-- | transform combination type
trCombType :: a -> (Int -> a) -> a -> (Int -> a) -> CombType -> a

-- | is type of combination FuncCall?
isCombTypeFuncCall :: CombType -> Bool

-- | is type of combination FuncPartCall?
isCombTypeFuncPartCall :: CombType -> Bool

-- | is type of combination ConsCall?
isCombTypeConsCall :: CombType -> Bool

-- | is type of combination ConsPartCall?
isCombTypeConsPartCall :: CombType -> Bool

-- | get internal number of variable
varNr :: Expr -> VarIndex

-- | get literal if expression is literal expression
literal :: Expr -> Literal

-- | get combination type of a combined expression
combType :: Expr -> CombType

-- | get name of a combined expression
combName :: Expr -> QName

-- | get arguments of a combined expression
combArgs :: Expr -> [Expr]

-- | get number of missing arguments if expression is combined
missingCombArgs :: Expr -> Int

-- | get indices of varoables in let declaration
letBinds :: Expr -> [(VarIndex, Expr)]

-- | get body of let declaration
letBody :: Expr -> Expr

-- | get variable indices from declaration of free variables
freeVars :: Expr -> [VarIndex]

-- | get expression from declaration of free variables
freeExpr :: Expr -> Expr

-- | get expressions from or-expression
orExps :: Expr -> [Expr]

-- | get case-type of case expression
caseType :: Expr -> CaseType

-- | get scrutinee of case expression
caseExpr :: Expr -> Expr

-- | get branch expressions from case expression
caseBranches :: Expr -> [BranchExpr]

-- | is expression a variable?
isVar :: Expr -> Bool

-- | is expression a literal expression?
isLit :: Expr -> Bool

-- | is expression combined?
isComb :: Expr -> Bool

-- | is expression a let expression?
isLet :: Expr -> Bool

-- | is expression a declaration of free variables?
isFree :: Expr -> Bool

-- | is expression an or-expression?
isOr :: Expr -> Bool

-- | is expression a case expression?
isCase :: Expr -> Bool

-- | transform expression
trExpr :: (VarIndex -> a) -> (Literal -> a) -> (CombType -> QName -> [a] -> a) -> ([(VarIndex, a)] -> a -> a) -> ([VarIndex] -> a -> a) -> (a -> a -> a) -> (SrcRef -> CaseType -> a -> [b] -> a) -> (Pattern -> a -> b) -> (a -> TypeExpr -> a) -> Expr -> a

-- | update all variables in given expression
updVars :: (VarIndex -> Expr) -> Expr -> Expr

-- | update all literals in given expression
updLiterals :: (Literal -> Expr) -> Expr -> Expr

-- | update all combined expressions in given expression
updCombs :: (CombType -> QName -> [Expr] -> Expr) -> Expr -> Expr

-- | update all let expressions in given expression
updLets :: ([(VarIndex, Expr)] -> Expr -> Expr) -> Expr -> Expr

-- | update all free declarations in given expression
updFrees :: ([VarIndex] -> Expr -> Expr) -> Expr -> Expr

-- | update all or expressions in given expression
updOrs :: (Expr -> Expr -> Expr) -> Expr -> Expr

-- | update all case expressions in given expression
updCases :: (SrcRef -> CaseType -> Expr -> [BranchExpr] -> Expr) -> Expr -> Expr

-- | update all case branches in given expression
updBranches :: (Pattern -> Expr -> BranchExpr) -> Expr -> Expr

-- | update all typed expressions in given expression
updTypeds :: (Expr -> TypeExpr -> Expr) -> Expr -> Expr

-- | is expression a call of a function where all arguments are provided?
isFuncCall :: Expr -> Bool

-- | is expression a partial function call?
isFuncPartCall :: Expr -> Bool

-- | is expression a call of a constructor?
isConsCall :: Expr -> Bool

-- | is expression a partial constructor call?
isConsPartCall :: Expr -> Bool

-- | is expression fully evaluated?
isGround :: Expr -> Bool

-- | get all variables (also pattern variables) in expression
allVars :: Expr -> [VarIndex]

-- | rename all variables (also in patterns) in expression
rnmAllVars :: Update Expr VarIndex

-- | update all qualified names in expression
updQNames :: Update Expr QName

-- | transform branch expression
trBranch :: (Pattern -> Expr -> a) -> BranchExpr -> a

-- | get pattern from branch expression
branchPattern :: BranchExpr -> Pattern

-- | get expression from branch expression
branchExpr :: BranchExpr -> Expr

-- | update branch expression
updBranch :: (Pattern -> Pattern) -> (Expr -> Expr) -> BranchExpr -> BranchExpr

-- | update pattern of branch expression
updBranchPattern :: Update BranchExpr Pattern

-- | update expression of branch expression
updBranchExpr :: Update BranchExpr Expr

-- | transform pattern
trPattern :: (QName -> [VarIndex] -> a) -> (Literal -> a) -> Pattern -> a

-- | get name from constructor pattern
patCons :: Pattern -> QName

-- | get arguments from constructor pattern
patArgs :: Pattern -> [VarIndex]

-- | get literal from literal pattern
patLiteral :: Pattern -> Literal

-- | is pattern a constructor pattern?
isConsPattern :: Pattern -> Bool

-- | update pattern
updPattern :: (QName -> QName) -> ([VarIndex] -> [VarIndex]) -> (Literal -> Literal) -> Pattern -> Pattern

-- | update constructors name of pattern
updPatCons :: (QName -> QName) -> Pattern -> Pattern

-- | update arguments of constructor pattern
updPatArgs :: ([VarIndex] -> [VarIndex]) -> Pattern -> Pattern

-- | update literal of pattern
updPatLiteral :: (Literal -> Literal) -> Pattern -> Pattern

-- | build expression from pattern
patExpr :: Pattern -> Expr

-- | Get the type of an expression. (Will only succeed if all VarIndices
--   and QNames contain the required type information. Make sure that the
--   expression is processed by
--   Curry.ExtendedFlat.TypeInference.adjustTypeInfo.)
typeofExpr :: Expr -> Maybe TypeExpr

-- | Get the type of a <a>Literal</a>.
typeofLiteral :: Literal -> TypeExpr

-- | Returns a list containing the identifiers that occur free in an
--   expression. (Not to confuse with Curry's free variables..)
fvs :: Expr -> [VarIndex]

-- | Is an expression in weak head normal form? Yes for literals,
--   constructor terms and unsaturated combinations.
whnf :: Expr -> Bool


-- | Erases type annotations in an ExtendedFlat module. In functions, it
--   preserves annotations that contain free type variables, i.e. type
--   variables which do not occur in the function's type signature.
--   
--   In the remaining type annotations, free type variables are replaced by
--   the unit type ().
--   
--   (c) 2009, Holger Siegel.
module Curry.ExtendedFlat.EraseTypes

-- | Erase type annotations
eraseTypes :: Prog -> Prog


module Curry.ExtendedFlat.InterfaceEquivalence

-- | Check whether the interfaces of two FlatCurry programs are equivalent.
eqInterface :: Prog -> Prog -> Bool
instance Curry.ExtendedFlat.InterfaceEquivalence.Equiv a => Curry.ExtendedFlat.InterfaceEquivalence.Equiv [a]
instance Curry.ExtendedFlat.InterfaceEquivalence.Equiv GHC.Types.Char
instance Curry.ExtendedFlat.InterfaceEquivalence.Equiv Curry.ExtendedFlat.Type.Prog
instance Curry.ExtendedFlat.InterfaceEquivalence.Equiv Curry.ExtendedFlat.Type.TypeDecl
instance Curry.ExtendedFlat.InterfaceEquivalence.Equiv Curry.ExtendedFlat.Type.FuncDecl
instance Curry.ExtendedFlat.InterfaceEquivalence.Equiv Curry.ExtendedFlat.Type.Rule
instance Curry.ExtendedFlat.InterfaceEquivalence.Equiv Curry.ExtendedFlat.Type.OpDecl


module Curry.ExtendedFlat.MonadicGoodies

-- | Monadic update of a type's component
type UpdateM m a b = (b -> m b) -> a -> m a

-- | Update an <a>Expr</a> in post-order
postOrderM :: Monad m => UpdateM m Expr Expr

-- | Update all <a>Expr</a>s in a function declaration in post-order
updFuncExpsM :: Monad m => UpdateM m FuncDecl Expr

-- | Update all <a>FuncDecl</a>s in a program
updProgFuncsM :: Monad m => UpdateM m Prog FuncDecl

-- | Update all let-declarations in a function declaration
updFuncLetsM :: Monad m => ([(VarIndex, Expr)] -> Expr -> m Expr) -> FuncDecl -> m FuncDecl


-- | Turn recursive data declarations into recursive function calls.
--   
--   Only single recursive declarations are transformed, mutually recursive
--   declarations are left unchanged. You should therefore use the
--   transformation UnMutual first.
module Curry.ExtendedFlat.LiftLetrec

-- | Convert recursive data declarations into recursive function calls
liftLetrecProg :: Prog -> Prog


-- | This module implements a pretty printer for ExtendedFlatCurry modules.
module Curry.ExtendedFlat.Pretty

-- | pretty-print a FlatCurry module
ppProg :: Prog -> Doc

-- | pretty-print the module header
ppHeader :: String -> [TypeDecl] -> [FuncDecl] -> Doc

-- | pretty-print the export list
ppExports :: [TypeDecl] -> [FuncDecl] -> Doc

-- | pretty-print an import statement
ppImport :: String -> Doc

-- | pretty-print a type declaration
ppTypeDecl :: TypeDecl -> Doc

-- | pretty-print a type expression
ppTypeExpr :: Int -> TypeExpr -> Doc

-- | pretty-print a function declaration
ppFuncDecl :: FuncDecl -> Doc

-- | pretty-print an expression
ppExpr :: Int -> Expr -> Doc

-- | pretty-print a literal
ppLiteral :: Literal -> Doc

-- | pretty-print a operator fixity declaration
ppOpDecl :: OpDecl -> Doc


module Curry.ExtendedFlat


-- | The function adjustTypeInfos annotates every declaration, identifier,
--   and application with exact type information.
--   
--   This information is derived from the more general information found in
--   the AST.
module Curry.ExtendedFlat.TypeInference

-- | Displays a <a>TypeExpr</a> as a <a>String</a>
dispType :: TypeExpr -> String

-- | For every identifier that occurs in the right hand side of a
--   declaration, the polymorphic type variables in its type label are
--   replaced by concrete types.
adjustTypeInfo :: Prog -> Prog

-- | All identifiers that do not have type annotations are labelled with
--   new type variables
labelVarsWithTypes :: Prog -> Prog

-- | Type variables that occur in the type annotations of QNames are
--   replaced by newly introduced type variables, so that further
--   unification steps will not interfere with parametric polymorphism
uniqueTypeIndices :: Prog -> Prog

-- | Specialises all type variables (part of adjustTypeInfo)
genEquations :: Prog -> Prog


-- | Turns mutually recursive declarations into a single recursive
--   declaration, of a tuple value, trying to minimize the number of the
--   tuple. This is an implementation of the algorithm described in
--   <a>http://www.informatik.uni-kiel.de/~mh/lehre/diplomarbeiten/siegel.pdf</a>
module Curry.ExtendedFlat.UnMutual

-- | Convert mutually recursive declarations into a single recursive
--   declaration using tuples.
unMutualProg :: Prog -> Prog


-- | This module contains functions for reading and writing FlatCurry
--   files.
module Curry.FlatCurry.Files

-- | Reads an ExtendedFlat file (extension ".efc") and eventually returns
--   the corresponding FlatCurry program term (type <a>Prog</a>).
readFlatCurry :: FilePath -> IO (Maybe Prog)

-- | Reads a FlatInterface file (extension <tt>.fint</tt>) and returns the
--   corresponding term (type <a>Prog</a>) as a value of type <a>Maybe</a>.
readFlatInterface :: FilePath -> IO (Maybe Prog)

-- | Writes a FlatCurry program term into a file.
writeFlatCurry :: FilePath -> Prog -> IO ()


module Curry.FlatCurry


-- | This module provides the data structures for Curry language
--   extensions.
module Curry.Syntax.Extension

-- | Specified language extensions, either known or unknown.
data Extension

-- | a known extension
KnownExtension :: Position -> KnownExtension -> Extension

-- | an unknown extension
UnknownExtension :: Position -> String -> Extension

-- | Known language extensions of Curry.
data KnownExtension

-- | anonymous free variables
AnonFreeVars :: KnownExtension

-- | functional patterns
FunctionalPatterns :: KnownExtension

-- | negative literals
NegativeLiterals :: KnownExtension

-- | no implicit import of the prelude
NoImplicitPrelude :: KnownExtension

-- | Classifies a <a>String</a> as an <a>Extension</a>
classifyExtension :: Ident -> Extension

-- | <a>Extension</a>s available by Kiel's Curry compilers.
kielExtensions :: [KnownExtension]

-- | Different Curry tools which may accept compiler options.
data Tool
KICS2 :: Tool
PAKCS :: Tool
CYMAKE :: Tool
UnknownTool :: String -> Tool

-- | Classifies a <a>String</a> as a <a>Tool</a>
classifyTool :: String -> Tool
instance Data.Data.Data Curry.Syntax.Extension.Tool
instance GHC.Show.Show Curry.Syntax.Extension.Tool
instance GHC.Read.Read Curry.Syntax.Extension.Tool
instance GHC.Classes.Eq Curry.Syntax.Extension.Tool
instance Data.Data.Data Curry.Syntax.Extension.Extension
instance GHC.Show.Show Curry.Syntax.Extension.Extension
instance GHC.Read.Read Curry.Syntax.Extension.Extension
instance GHC.Classes.Eq Curry.Syntax.Extension.Extension
instance Data.Data.Data Curry.Syntax.Extension.KnownExtension
instance GHC.Enum.Bounded Curry.Syntax.Extension.KnownExtension
instance GHC.Enum.Enum Curry.Syntax.Extension.KnownExtension
instance GHC.Show.Show Curry.Syntax.Extension.KnownExtension
instance GHC.Read.Read Curry.Syntax.Extension.KnownExtension
instance GHC.Classes.Eq Curry.Syntax.Extension.KnownExtension
instance Curry.Base.Position.HasPosition Curry.Syntax.Extension.Extension


-- | This module provides the necessary data structures to maintain the
--   parsed representation of a Curry pProgram.
module Curry.Syntax.Type

-- | Curry module
data Module
Module :: [ModulePragma] -> ModuleIdent -> (Maybe ExportSpec) -> [ImportDecl] -> [Decl] -> Module

-- | Module pragma
data ModulePragma

-- | language pragma
LanguagePragma :: Position -> [Extension] -> ModulePragma

-- | options pragma
OptionsPragma :: Position -> (Maybe Tool) -> String -> ModulePragma

-- | Specified language extensions, either known or unknown.
data Extension

-- | a known extension
KnownExtension :: Position -> KnownExtension -> Extension

-- | an unknown extension
UnknownExtension :: Position -> String -> Extension

-- | Known language extensions of Curry.
data KnownExtension

-- | anonymous free variables
AnonFreeVars :: KnownExtension

-- | functional patterns
FunctionalPatterns :: KnownExtension

-- | negative literals
NegativeLiterals :: KnownExtension

-- | no implicit import of the prelude
NoImplicitPrelude :: KnownExtension

-- | Different Curry tools which may accept compiler options.
data Tool
KICS2 :: Tool
PAKCS :: Tool
CYMAKE :: Tool
UnknownTool :: String -> Tool

-- | Export specification
data ExportSpec
Exporting :: Position -> [Export] -> ExportSpec

-- | Single exported entity
data Export
Export :: QualIdent -> Export
ExportTypeWith :: QualIdent -> [Ident] -> Export
ExportTypeAll :: QualIdent -> Export
ExportModule :: ModuleIdent -> Export

-- | Import declaration
data ImportDecl
ImportDecl :: Position -> ModuleIdent -> Qualified -> (Maybe ModuleIdent) -> (Maybe ImportSpec) -> ImportDecl

-- | Import specification
data ImportSpec
Importing :: Position -> [Import] -> ImportSpec
Hiding :: Position -> [Import] -> ImportSpec

-- | Single imported entity
data Import
Import :: Ident -> Import
ImportTypeWith :: Ident -> [Ident] -> Import
ImportTypeAll :: Ident -> Import

-- | Flag to signal qualified import
type Qualified = Bool

-- | Module interface
--   
--   Interface declarations are restricted to type declarations and
--   signatures. Note that an interface function declaration additionaly
--   contains the function arity (= number of parameters) in order to
--   generate correct FlatCurry function applications.
data Interface
Interface :: ModuleIdent -> [IImportDecl] -> [IDecl] -> Interface

-- | Interface import declaration
data IImportDecl
IImportDecl :: Position -> ModuleIdent -> IImportDecl

-- | Arity of a function
type Arity = Int

-- | Interface declaration
data IDecl
IInfixDecl :: Position -> Infix -> Precedence -> QualIdent -> IDecl
HidingDataDecl :: Position -> QualIdent -> [Ident] -> IDecl
IDataDecl :: Position -> QualIdent -> [Ident] -> [ConstrDecl] -> [Ident] -> IDecl
INewtypeDecl :: Position -> QualIdent -> [Ident] -> NewConstrDecl -> [Ident] -> IDecl
ITypeDecl :: Position -> QualIdent -> [Ident] -> TypeExpr -> IDecl
IFunctionDecl :: Position -> QualIdent -> Arity -> TypeExpr -> IDecl

-- | Declaration in a module
data Decl
InfixDecl :: Position -> Infix -> (Maybe Precedence) -> [Ident] -> Decl
DataDecl :: Position -> Ident -> [Ident] -> [ConstrDecl] -> Decl
NewtypeDecl :: Position -> Ident -> [Ident] -> NewConstrDecl -> Decl
TypeDecl :: Position -> Ident -> [Ident] -> TypeExpr -> Decl
TypeSig :: Position -> [Ident] -> TypeExpr -> Decl
FunctionDecl :: Position -> Ident -> [Equation] -> Decl
ForeignDecl :: Position -> CallConv -> (Maybe String) -> Ident -> TypeExpr -> Decl
ExternalDecl :: Position -> [Ident] -> Decl
PatternDecl :: Position -> Pattern -> Rhs -> Decl
FreeDecl :: Position -> [Ident] -> Decl

-- | Operator precedence
type Precedence = Integer

-- | Fixity of operators
data Infix

-- | left-associative
InfixL :: Infix

-- | right-associative
InfixR :: Infix

-- | no associativity
Infix :: Infix

-- | Constructor declaration for algebraic data types
data ConstrDecl
ConstrDecl :: Position -> [Ident] -> Ident -> [TypeExpr] -> ConstrDecl
ConOpDecl :: Position -> [Ident] -> TypeExpr -> Ident -> TypeExpr -> ConstrDecl
RecordDecl :: Position -> [Ident] -> Ident -> [FieldDecl] -> ConstrDecl

-- | Constructor declaration for renaming types (newtypes)
data NewConstrDecl
NewConstrDecl :: Position -> [Ident] -> Ident -> TypeExpr -> NewConstrDecl
NewRecordDecl :: Position -> [Ident] -> Ident -> (Ident, TypeExpr) -> NewConstrDecl

-- | Declaration for labelled fields
data FieldDecl
FieldDecl :: Position -> [Ident] -> TypeExpr -> FieldDecl

-- | Calling convention for C code
data CallConv
CallConvPrimitive :: CallConv
CallConvCCall :: CallConv

-- | Type expressions
data TypeExpr
ConstructorType :: QualIdent -> [TypeExpr] -> TypeExpr
VariableType :: Ident -> TypeExpr
TupleType :: [TypeExpr] -> TypeExpr
ListType :: TypeExpr -> TypeExpr
ArrowType :: TypeExpr -> TypeExpr -> TypeExpr
ParenType :: TypeExpr -> TypeExpr

-- | Function defining equation
data Equation
Equation :: Position -> Lhs -> Rhs -> Equation

-- | Left-hand-side of an <a>Equation</a> (function identifier and
--   patterns)
data Lhs
FunLhs :: Ident -> [Pattern] -> Lhs
OpLhs :: Pattern -> Ident -> Pattern -> Lhs
ApLhs :: Lhs -> [Pattern] -> Lhs

-- | Right-hand-side of an <a>Equation</a>
data Rhs
SimpleRhs :: Position -> Expression -> [Decl] -> Rhs
GuardedRhs :: [CondExpr] -> [Decl] -> Rhs

-- | Conditional expression (expression conditioned by a guard)
data CondExpr
CondExpr :: Position -> Expression -> Expression -> CondExpr

-- | Literal The <a>Ident</a> argument of an <tt>Int</tt> literal is used
--   for supporting ad-hoc polymorphism on integer numbers. An integer
--   literal can be used either as an integer number or as a floating-point
--   number depending on its context. The compiler uses the identifier of
--   the <tt>Int</tt> literal for maintaining its type.
data Literal
Char :: SrcRef -> Char -> Literal
Int :: Ident -> Integer -> Literal
Float :: SrcRef -> Double -> Literal
String :: SrcRef -> String -> Literal

-- | Constructor term (used for patterns)
data Pattern
LiteralPattern :: Literal -> Pattern
NegativePattern :: Ident -> Literal -> Pattern
VariablePattern :: Ident -> Pattern
ConstructorPattern :: QualIdent -> [Pattern] -> Pattern
InfixPattern :: Pattern -> QualIdent -> Pattern -> Pattern
ParenPattern :: Pattern -> Pattern
RecordPattern :: QualIdent -> [Field Pattern] -> Pattern
TuplePattern :: SrcRef -> [Pattern] -> Pattern
ListPattern :: [SrcRef] -> [Pattern] -> Pattern
AsPattern :: Ident -> Pattern -> Pattern
LazyPattern :: SrcRef -> Pattern -> Pattern
FunctionPattern :: QualIdent -> [Pattern] -> Pattern
InfixFuncPattern :: Pattern -> QualIdent -> Pattern -> Pattern

-- | Expression
data Expression
Literal :: Literal -> Expression
Variable :: QualIdent -> Expression
Constructor :: QualIdent -> Expression
Paren :: Expression -> Expression
Typed :: Expression -> TypeExpr -> Expression
Record :: QualIdent -> [Field Expression] -> Expression
RecordUpdate :: Expression -> [Field Expression] -> Expression
Tuple :: SrcRef -> [Expression] -> Expression
List :: [SrcRef] -> [Expression] -> Expression
ListCompr :: SrcRef -> Expression -> [Statement] -> Expression
EnumFrom :: Expression -> Expression
EnumFromThen :: Expression -> Expression -> Expression
EnumFromTo :: Expression -> Expression -> Expression
EnumFromThenTo :: Expression -> Expression -> Expression -> Expression
UnaryMinus :: Ident -> Expression -> Expression
Apply :: Expression -> Expression -> Expression
InfixApply :: Expression -> InfixOp -> Expression -> Expression
LeftSection :: Expression -> InfixOp -> Expression
RightSection :: InfixOp -> Expression -> Expression
Lambda :: SrcRef -> [Pattern] -> Expression -> Expression
Let :: [Decl] -> Expression -> Expression
Do :: [Statement] -> Expression -> Expression
IfThenElse :: SrcRef -> Expression -> Expression -> Expression -> Expression
Case :: SrcRef -> CaseType -> Expression -> [Alt] -> Expression

-- | Infix operation
data InfixOp
InfixOp :: QualIdent -> InfixOp
InfixConstr :: QualIdent -> InfixOp

-- | Statement (used for do-sequence and list comprehensions)
data Statement
StmtExpr :: SrcRef -> Expression -> Statement
StmtDecl :: [Decl] -> Statement
StmtBind :: SrcRef -> Pattern -> Expression -> Statement

-- | Type of case expressions
data CaseType
Rigid :: CaseType
Flex :: CaseType

-- | Single case alternative
data Alt
Alt :: Position -> Pattern -> Rhs -> Alt

-- | Record field
data Field a
Field :: Position -> QualIdent -> a -> Field a

-- | Goal in REPL (expression to evaluate)
data Goal
Goal :: Position -> Expression -> [Decl] -> Goal
instance Data.Data.Data Curry.Syntax.Type.Goal
instance GHC.Show.Show Curry.Syntax.Type.Goal
instance GHC.Read.Read Curry.Syntax.Type.Goal
instance GHC.Classes.Eq Curry.Syntax.Type.Goal
instance Data.Data.Data Curry.Syntax.Type.Module
instance GHC.Show.Show Curry.Syntax.Type.Module
instance GHC.Read.Read Curry.Syntax.Type.Module
instance GHC.Classes.Eq Curry.Syntax.Type.Module
instance Data.Data.Data Curry.Syntax.Type.Equation
instance GHC.Show.Show Curry.Syntax.Type.Equation
instance GHC.Read.Read Curry.Syntax.Type.Equation
instance GHC.Classes.Eq Curry.Syntax.Type.Equation
instance Data.Data.Data Curry.Syntax.Type.CondExpr
instance GHC.Show.Show Curry.Syntax.Type.CondExpr
instance GHC.Read.Read Curry.Syntax.Type.CondExpr
instance GHC.Classes.Eq Curry.Syntax.Type.CondExpr
instance Data.Data.Data Curry.Syntax.Type.Statement
instance GHC.Show.Show Curry.Syntax.Type.Statement
instance GHC.Read.Read Curry.Syntax.Type.Statement
instance GHC.Classes.Eq Curry.Syntax.Type.Statement
instance Data.Data.Data Curry.Syntax.Type.Alt
instance GHC.Show.Show Curry.Syntax.Type.Alt
instance GHC.Read.Read Curry.Syntax.Type.Alt
instance GHC.Classes.Eq Curry.Syntax.Type.Alt
instance Data.Data.Data Curry.Syntax.Type.Expression
instance GHC.Show.Show Curry.Syntax.Type.Expression
instance GHC.Read.Read Curry.Syntax.Type.Expression
instance GHC.Classes.Eq Curry.Syntax.Type.Expression
instance Data.Data.Data Curry.Syntax.Type.Rhs
instance GHC.Show.Show Curry.Syntax.Type.Rhs
instance GHC.Read.Read Curry.Syntax.Type.Rhs
instance GHC.Classes.Eq Curry.Syntax.Type.Rhs
instance Data.Data.Data Curry.Syntax.Type.Decl
instance GHC.Show.Show Curry.Syntax.Type.Decl
instance GHC.Read.Read Curry.Syntax.Type.Decl
instance GHC.Classes.Eq Curry.Syntax.Type.Decl
instance Data.Data.Data Curry.Syntax.Type.Lhs
instance GHC.Show.Show Curry.Syntax.Type.Lhs
instance GHC.Read.Read Curry.Syntax.Type.Lhs
instance GHC.Classes.Eq Curry.Syntax.Type.Lhs
instance Data.Data.Data Curry.Syntax.Type.Pattern
instance GHC.Show.Show Curry.Syntax.Type.Pattern
instance GHC.Read.Read Curry.Syntax.Type.Pattern
instance GHC.Classes.Eq Curry.Syntax.Type.Pattern
instance Data.Data.Data a => Data.Data.Data (Curry.Syntax.Type.Field a)
instance GHC.Show.Show a => GHC.Show.Show (Curry.Syntax.Type.Field a)
instance GHC.Read.Read a => GHC.Read.Read (Curry.Syntax.Type.Field a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Curry.Syntax.Type.Field a)
instance Data.Data.Data Curry.Syntax.Type.CaseType
instance GHC.Show.Show Curry.Syntax.Type.CaseType
instance GHC.Read.Read Curry.Syntax.Type.CaseType
instance GHC.Classes.Eq Curry.Syntax.Type.CaseType
instance Data.Data.Data Curry.Syntax.Type.InfixOp
instance GHC.Show.Show Curry.Syntax.Type.InfixOp
instance GHC.Read.Read Curry.Syntax.Type.InfixOp
instance GHC.Classes.Eq Curry.Syntax.Type.InfixOp
instance Data.Data.Data Curry.Syntax.Type.Literal
instance GHC.Show.Show Curry.Syntax.Type.Literal
instance GHC.Read.Read Curry.Syntax.Type.Literal
instance GHC.Classes.Eq Curry.Syntax.Type.Literal
instance Data.Data.Data Curry.Syntax.Type.Interface
instance GHC.Show.Show Curry.Syntax.Type.Interface
instance GHC.Read.Read Curry.Syntax.Type.Interface
instance GHC.Classes.Eq Curry.Syntax.Type.Interface
instance Data.Data.Data Curry.Syntax.Type.IDecl
instance GHC.Show.Show Curry.Syntax.Type.IDecl
instance GHC.Read.Read Curry.Syntax.Type.IDecl
instance GHC.Classes.Eq Curry.Syntax.Type.IDecl
instance Data.Data.Data Curry.Syntax.Type.ConstrDecl
instance GHC.Show.Show Curry.Syntax.Type.ConstrDecl
instance GHC.Read.Read Curry.Syntax.Type.ConstrDecl
instance GHC.Classes.Eq Curry.Syntax.Type.ConstrDecl
instance Data.Data.Data Curry.Syntax.Type.NewConstrDecl
instance GHC.Show.Show Curry.Syntax.Type.NewConstrDecl
instance GHC.Read.Read Curry.Syntax.Type.NewConstrDecl
instance GHC.Classes.Eq Curry.Syntax.Type.NewConstrDecl
instance Data.Data.Data Curry.Syntax.Type.FieldDecl
instance GHC.Show.Show Curry.Syntax.Type.FieldDecl
instance GHC.Read.Read Curry.Syntax.Type.FieldDecl
instance GHC.Classes.Eq Curry.Syntax.Type.FieldDecl
instance Data.Data.Data Curry.Syntax.Type.TypeExpr
instance GHC.Show.Show Curry.Syntax.Type.TypeExpr
instance GHC.Read.Read Curry.Syntax.Type.TypeExpr
instance GHC.Classes.Eq Curry.Syntax.Type.TypeExpr
instance Data.Data.Data Curry.Syntax.Type.CallConv
instance GHC.Show.Show Curry.Syntax.Type.CallConv
instance GHC.Read.Read Curry.Syntax.Type.CallConv
instance GHC.Classes.Eq Curry.Syntax.Type.CallConv
instance Data.Data.Data Curry.Syntax.Type.Infix
instance GHC.Show.Show Curry.Syntax.Type.Infix
instance GHC.Read.Read Curry.Syntax.Type.Infix
instance GHC.Classes.Eq Curry.Syntax.Type.Infix
instance Data.Data.Data Curry.Syntax.Type.IImportDecl
instance GHC.Show.Show Curry.Syntax.Type.IImportDecl
instance GHC.Read.Read Curry.Syntax.Type.IImportDecl
instance GHC.Classes.Eq Curry.Syntax.Type.IImportDecl
instance Data.Data.Data Curry.Syntax.Type.ImportDecl
instance GHC.Show.Show Curry.Syntax.Type.ImportDecl
instance GHC.Read.Read Curry.Syntax.Type.ImportDecl
instance GHC.Classes.Eq Curry.Syntax.Type.ImportDecl
instance Data.Data.Data Curry.Syntax.Type.ImportSpec
instance GHC.Show.Show Curry.Syntax.Type.ImportSpec
instance GHC.Read.Read Curry.Syntax.Type.ImportSpec
instance GHC.Classes.Eq Curry.Syntax.Type.ImportSpec
instance Data.Data.Data Curry.Syntax.Type.Import
instance GHC.Show.Show Curry.Syntax.Type.Import
instance GHC.Read.Read Curry.Syntax.Type.Import
instance GHC.Classes.Eq Curry.Syntax.Type.Import
instance Data.Data.Data Curry.Syntax.Type.ExportSpec
instance GHC.Show.Show Curry.Syntax.Type.ExportSpec
instance GHC.Read.Read Curry.Syntax.Type.ExportSpec
instance GHC.Classes.Eq Curry.Syntax.Type.ExportSpec
instance Data.Data.Data Curry.Syntax.Type.Export
instance GHC.Show.Show Curry.Syntax.Type.Export
instance GHC.Read.Read Curry.Syntax.Type.Export
instance GHC.Classes.Eq Curry.Syntax.Type.Export
instance Data.Data.Data Curry.Syntax.Type.ModulePragma
instance GHC.Show.Show Curry.Syntax.Type.ModulePragma
instance GHC.Read.Read Curry.Syntax.Type.ModulePragma
instance GHC.Classes.Eq Curry.Syntax.Type.ModulePragma
instance Curry.Base.Position.SrcRefOf Curry.Syntax.Type.Pattern
instance Curry.Base.Position.SrcRefOf Curry.Syntax.Type.Literal


-- | Transform a CurrySyntax module into a string representation without
--   any pretty printing.
--   
--   Behaves like a derived Show instance even on parts with a specific
--   one.
module Curry.Syntax.ShowModule

-- | Show a Curry module like by an devired <a>Show</a> instance
showModule :: Module -> String


-- | This module provides some utility functions for working with the
--   abstract syntax tree of Curry.
module Curry.Syntax.Utils

-- | Check whether a <a>Module</a> has a specific <a>KnownExtension</a>
--   enabled by a pragma
hasLanguageExtension :: Module -> KnownExtension -> Bool

-- | Extract all known extensions from a <a>Module</a>
knownExtensions :: Module -> [KnownExtension]

-- | Is the declaration a type signature?
isTypeSig :: Decl -> Bool

-- | Convert an infix operator into an expression
infixOp :: InfixOp -> Expression

-- | Is the declaration a type declaration?
isTypeDecl :: Decl -> Bool

-- | Is the declaration a value declaration?
isValueDecl :: Decl -> Bool

-- | Is the declaration an infix declaration?
isInfixDecl :: Decl -> Bool

-- | Is the declaration a function declaration?
isFunctionDecl :: Decl -> Bool

-- | Is the declaration an external declaration?
isExternalDecl :: Decl -> Bool

-- | Replace the generic module name <tt>main</tt> with the module name
--   derived from the <a>FilePath</a> of the module.
patchModuleId :: FilePath -> Module -> Module

-- | flatten the left-hand-side to the identifier and all constructor terms
flatLhs :: Lhs -> (Ident, [Pattern])

-- | Construct an Integer literal
mkInt :: Integer -> Literal

-- | Select the label of a field
fieldLabel :: Field a -> QualIdent

-- | Select the term of a field
fieldTerm :: Field a -> a

-- | Select the label and term of a field
field2Tuple :: Field a -> (QualIdent, a)

-- | Get the operator name of an infix operator
opName :: InfixOp -> QualIdent

-- | Add <a>SrcRef</a>s to a <a>Module</a>
addSrcRefs :: Module -> Module

-- | Get the identifier of a constructor declaration
constrId :: ConstrDecl -> Ident

-- | Get the identifier of a newtype constructor declaration
nconstrId :: NewConstrDecl -> Ident

-- | Get record label identifiers of a constructor declaration
recordLabels :: ConstrDecl -> [Ident]

-- | Get record label identifier of a newtype constructor declaration
nrecordLabels :: NewConstrDecl -> [Ident]


-- | The Curry parser is implemented using the (mostly) LL(1) parsing
--   combinators implemented in <a>LLParseComb</a>.
module Curry.Syntax.Parser

-- | Parse a <a>Module</a>
parseSource :: FilePath -> String -> CYM Module

-- | Parse a <a>Module</a> header
parseHeader :: FilePath -> String -> CYM Module

-- | Parse an <a>Interface</a>
parseInterface :: FilePath -> String -> CYM Interface

-- | Parse a <a>Goal</a>
parseGoal :: String -> CYM Goal


-- | This module implements a pretty printer for Curry expressions. It was
--   derived from the Haskell pretty printer provided in Simon Marlow's
--   Haskell parser.
module Curry.Syntax.Pretty

-- | Pretty print a module
ppModule :: Module -> Doc

-- | Pretty print an interface
ppInterface :: Interface -> Doc

-- | Pretty print an interface declaration
ppIDecl :: IDecl -> Doc

-- | Pretty print a declaration
ppDecl :: Decl -> Doc

-- | Pretty print an identifier
ppIdent :: Ident -> Doc

-- | Pretty print a constructor term
ppPattern :: Int -> Pattern -> Doc

-- | Pretty print a record field pattern
ppFieldPatt :: Field Pattern -> Doc

-- | Pretty print an expression
ppExpr :: Int -> Expression -> Doc

-- | Pretty print an operator
ppOp :: InfixOp -> Doc

-- | Pretty print a statement
ppStmt :: Statement -> Doc

-- | Pretty print a record field expression (Haskell syntax)
ppFieldExpr :: Field Expression -> Doc

-- | Pretty print a type expression
ppTypeExpr :: Int -> TypeExpr -> Doc

-- | Pretty print an alternative in a case expression
ppAlt :: Alt -> Doc


module Curry.Syntax

-- | Data type for curry lexer tokens
data Token
Token :: Category -> Attributes -> Token

-- | Category of curry tokens
data Category
CharTok :: Category
IntTok :: Category
FloatTok :: Category
StringTok :: Category
Id :: Category
QId :: Category
Sym :: Category
QSym :: Category
LeftParen :: Category
RightParen :: Category
Semicolon :: Category
LeftBrace :: Category
RightBrace :: Category
LeftBracket :: Category
RightBracket :: Category
Comma :: Category
Underscore :: Category
Backquote :: Category
VSemicolon :: Category
VRightBrace :: Category
KW_case :: Category
KW_data :: Category
KW_do :: Category
KW_else :: Category
KW_external :: Category
KW_fcase :: Category
KW_foreign :: Category
KW_free :: Category
KW_if :: Category
KW_import :: Category
KW_in :: Category
KW_infix :: Category
KW_infixl :: Category
KW_infixr :: Category
KW_let :: Category
KW_module :: Category
KW_newtype :: Category
KW_of :: Category
KW_then :: Category
KW_type :: Category
KW_where :: Category
At :: Category
Colon :: Category
DotDot :: Category
DoubleColon :: Category
Equals :: Category
Backslash :: Category
Bar :: Category
LeftArrow :: Category
RightArrow :: Category
Tilde :: Category
Id_as :: Category
Id_ccall :: Category
Id_forall :: Category
Id_hiding :: Category
Id_interface :: Category
Id_primitive :: Category
Id_qualified :: Category
SymDot :: Category
SymMinus :: Category
SymMinusDot :: Category
PragmaLanguage :: Category
PragmaOptions :: Category
PragmaHiding :: Category
PragmaEnd :: Category
LineComment :: Category
NestedComment :: Category
EOF :: Category

-- | Attributes associated to a token
data Attributes
NoAttributes :: Attributes
CharAttributes :: Char -> String -> Attributes
[cval] :: Attributes -> Char
[original] :: Attributes -> String
IntAttributes :: Integer -> String -> Attributes
[ival] :: Attributes -> Integer
[original] :: Attributes -> String
FloatAttributes :: Double -> String -> Attributes
[fval] :: Attributes -> Double
[original] :: Attributes -> String
StringAttributes :: String -> String -> Attributes
[sval] :: Attributes -> String
[original] :: Attributes -> String
IdentAttributes :: [String] -> String -> Attributes
[modulVal] :: Attributes -> [String]
[sval] :: Attributes -> String
OptionsAttributes :: Maybe String -> String -> Attributes
[toolVal] :: Attributes -> Maybe String
[toolArgs] :: Attributes -> String

-- | Unliterate a LiterateCurry file, identity on normal Curry file.
unlit :: FilePath -> String -> CYM String

-- | Unliterate and return the result of a lexical analysis of the source
--   program <tt>src</tt>. The result is a list of tuples consisting of a
--   <a>Span</a> and a <tt>Token</tt>.
unlitLexSource :: FilePath -> String -> CYM [(Span, Token)]

-- | Unliterate and parse a Curry <a>Module</a> header
unlitParseHeader :: FilePath -> String -> CYM Module

-- | Unliterate and parse a Curry <a>Module</a>
unlitParseModule :: FilePath -> String -> CYM Module

-- | Return the result of a lexical analysis of the source program
--   <tt>src</tt>. The result is a list of tuples consisting of a
--   <a>Span</a> and a <tt>Token</tt>.
lexSource :: FilePath -> String -> CYM [(Span, Token)]

-- | Parse a Curry <a>Interface</a>
parseInterface :: FilePath -> String -> CYM Interface

-- | Parse a Curry <a>Module</a> header
parseHeader :: FilePath -> String -> CYM Module

-- | Parse a Curry <a>Module</a>
parseModule :: FilePath -> String -> CYM Module

-- | Parse a <a>Goal</a>, i.e. an expression with (optional) local
--   declarations
parseGoal :: String -> CYM Goal

-- | Pretty print a module
ppModule :: Module -> Doc

-- | Pretty print an interface
ppInterface :: Interface -> Doc

-- | Pretty print an interface declaration
ppIDecl :: IDecl -> Doc

-- | Show a Curry module like by an devired <a>Show</a> instance
showModule :: Module -> String


-- | If a module is recompiled, the compiler has to check whether the
--   interface file must be updated. This must be done if any exported
--   entity has been changed, or an export was removed or added. The
--   function <a>intfEquiv</a> checks whether two interfaces are
--   equivalent, i.e., whether they define the same entities.
module Curry.Syntax.InterfaceEquivalence

-- | Disambiguate nullary type constructors and type variables.
fixInterface :: Interface -> Interface

-- | Are two given interfaces equivalent?
intfEquiv :: Interface -> Interface -> Bool
instance Curry.Syntax.InterfaceEquivalence.Equiv a => Curry.Syntax.InterfaceEquivalence.Equiv (GHC.Base.Maybe a)
instance Curry.Syntax.InterfaceEquivalence.Equiv a => Curry.Syntax.InterfaceEquivalence.Equiv [a]
instance Curry.Syntax.InterfaceEquivalence.Equiv Curry.Syntax.Type.Interface
instance Curry.Syntax.InterfaceEquivalence.Equiv Curry.Syntax.Type.IImportDecl
instance Curry.Syntax.InterfaceEquivalence.Equiv Curry.Syntax.Type.IDecl
instance Curry.Syntax.InterfaceEquivalence.Equiv Curry.Syntax.Type.ConstrDecl
instance Curry.Syntax.InterfaceEquivalence.Equiv Curry.Syntax.Type.FieldDecl
instance Curry.Syntax.InterfaceEquivalence.Equiv Curry.Syntax.Type.NewConstrDecl
instance Curry.Syntax.InterfaceEquivalence.Equiv Curry.Base.Ident.Ident
instance Curry.Syntax.InterfaceEquivalence.FixInterface a => Curry.Syntax.InterfaceEquivalence.FixInterface (GHC.Base.Maybe a)
instance Curry.Syntax.InterfaceEquivalence.FixInterface a => Curry.Syntax.InterfaceEquivalence.FixInterface [a]
instance Curry.Syntax.InterfaceEquivalence.FixInterface Curry.Syntax.Type.IDecl
instance Curry.Syntax.InterfaceEquivalence.FixInterface Curry.Syntax.Type.ConstrDecl
instance Curry.Syntax.InterfaceEquivalence.FixInterface Curry.Syntax.Type.FieldDecl
instance Curry.Syntax.InterfaceEquivalence.FixInterface Curry.Syntax.Type.NewConstrDecl
instance Curry.Syntax.InterfaceEquivalence.FixInterface Curry.Syntax.Type.TypeExpr


-- | This library contains a definition for representing Curry programs in
--   Haskell by the type <a>CurryProg</a> 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.
module Curry.AbstractCurry.Type

-- | A Curry module in the intermediate form. A value of this type has the
--   form <tt> CurryProg modname imports typedecls funcdecls opdecls </tt>
--   where [<tt>modname</tt>] Name of this module [<tt>imports</tt>] List
--   of modules names that are imported [<tt>typedecls</tt>] Type
--   declarations [<tt>funcdecls</tt>] Function declarations [<tt>
--   opdecls</tt>] Operator precedence declarations
data CurryProg
CurryProg :: MName -> [MName] -> [CTypeDecl] -> [CFuncDecl] -> [COpDecl] -> CurryProg

-- | A module name.
type MName = String

-- | 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.
type QName = (MName, String)

-- | Data type to specify the visibility of various entities.
data CVisibility

-- | exported entity
Public :: CVisibility

-- | private entity
Private :: CVisibility

-- | The type for representing type variables. They are represented by
--   <tt>(i,n)</tt> where <tt>i</tt> is a type variable index which is
--   unique inside a function and <tt>n</tt> is a name (if possible, the
--   name written in the source program).
type CTVarIName = (Int, String)

-- | Definitions of algebraic data types and type synonyms. A data type
--   definition of the form <tt> data t x1...xn = ...| c t1....tkc |...
--   </tt> is represented by the Curry term <tt> (CType t v [i1,...,in]
--   [...(CCons c kc v [t1,...,tkc])...]) </tt> where each <tt>ij</tt> is
--   the index of the type variable <tt>xj</tt> and <tt>v</tt> is the
--   visibility of the type resp. constructor. <i>Note:</i> 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.
data CTypeDecl

-- | algebraic data type
CType :: QName -> CVisibility -> [CTVarIName] -> [CConsDecl] -> CTypeDecl

-- | type synonym
CTypeSyn :: QName -> CVisibility -> [CTVarIName] -> CTypeExpr -> CTypeDecl

-- | renaming type, may have only exactly one type expression in the
--   constructor declaration
CNewType :: QName -> CVisibility -> [CTVarIName] -> CConsDecl -> CTypeDecl

-- | A constructor declaration consists of the name of the constructor and
--   a list of the argument types of the constructor. The arity equals the
--   number of types.
data CConsDecl
CCons :: QName -> CVisibility -> [CTypeExpr] -> CConsDecl
CRecord :: QName -> CVisibility -> [CFieldDecl] -> CConsDecl

-- | A record field declaration consists of the name of the the label, the
--   visibility and its corresponding type.
data CFieldDecl
CField :: QName -> CVisibility -> CTypeExpr -> CFieldDecl

-- | Type expression. A type expression is either a type variable, a
--   function type, or a type constructor application.
data CTypeExpr

-- | Type variable
CTVar :: CTVarIName -> CTypeExpr

-- | Function type <tt>t1 -&gt; t2</tt>
CFuncType :: CTypeExpr -> CTypeExpr -> CTypeExpr

-- | Type constructor application
CTCons :: QName -> [CTypeExpr] -> CTypeExpr

-- | Operator precedence declaration. An operator precedence declaration
--   <tt>fix p n</tt> in Curry corresponds to the AbstractCurry term
--   <tt>(COp n fix p)</tt>.
data COpDecl
COp :: QName -> CFixity -> Int -> COpDecl

-- | Fixity declarations of infix operators
data CFixity

-- | non-associative infix operator
CInfixOp :: CFixity

-- | left-associative infix operator
CInfixlOp :: CFixity

-- | right-associative infix operator
CInfixrOp :: CFixity

-- | Function arity
type Arity = Int

-- | Data type for representing function declarations. A function
--   declaration in FlatCurry is a term of the form <tt> (CFunc name arity
--   visibility type (CRules eval [CRule rule1,...,rulek])) </tt> and
--   represents the function <tt>name</tt> with definition <tt> name ::
--   type rule1 ... rulek </tt> <i>Note:</i> The variable indices are
--   unique inside each rule. External functions are represented as <tt>
--   (CFunc name arity type (CExternal s)) </tt> 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.
data CFuncDecl
CFunc :: QName -> Arity -> CVisibility -> CTypeExpr -> [CRule] -> CFuncDecl

-- | Right-hand-side of a <a>CRule</a> or an <tt>case</tt> expression
data CRhs
CSimpleRhs :: CExpr -> [CLocalDecl] -> CRhs
CGuardedRhs :: [(CExpr, CExpr)] -> [CLocalDecl] -> CRhs

-- | The general form of a function rule. It consists of a list of patterns
--   (left-hand side), a list of guards (<tt>success</tt> if not present in
--   the source text) with their corresponding right-hand sides, and a list
--   of local declarations.
data CRule
CRule :: [CPattern] -> CRhs -> CRule

-- | Local (let/where) declarations
data CLocalDecl

-- | local function declaration
CLocalFunc :: CFuncDecl -> CLocalDecl

-- | local pattern declaration
CLocalPat :: CPattern -> CRhs -> CLocalDecl

-- | local free variable declarations
CLocalVars :: [CVarIName] -> CLocalDecl

-- | Variable names. Object variables occurring in expressions are
--   represented by <tt>(Var i)</tt> where <tt>i</tt> is a variable index.
type CVarIName = (Int, String)

-- | Curry expressions.
data CExpr

-- | variable (unique index / name)
CVar :: CVarIName -> CExpr

-- | literal (Integer<i>Float</i>Char/String constant)
CLit :: CLiteral -> CExpr

-- | a defined symbol with module and name, i.e., a function or a
--   constructor
CSymbol :: QName -> CExpr

-- | application (e1 e2)
CApply :: CExpr -> CExpr -> CExpr

-- | lambda abstraction
CLambda :: [CPattern] -> CExpr -> CExpr

-- | local let declarations
CLetDecl :: [CLocalDecl] -> CExpr -> CExpr

-- | do block
CDoExpr :: [CStatement] -> CExpr

-- | list comprehension
CListComp :: CExpr -> [CStatement] -> CExpr

-- | case expression
CCase :: CCaseType -> CExpr -> [(CPattern, CRhs)] -> CExpr

-- | typed expression
CTyped :: CExpr -> CTypeExpr -> CExpr

-- | record construction (extended Curry)
CRecConstr :: QName -> [CField CExpr] -> CExpr

-- | record update (extended Curry)
CRecUpdate :: CExpr -> [CField CExpr] -> CExpr

-- | Type of case expressions
data CCaseType

-- | rigid case expression
CRigid :: CCaseType

-- | flexible case expression
CFlex :: CCaseType

-- | Statements in do expressions and list comprehensions.
data CStatement

-- | an expression (I/O action or boolean)
CSExpr :: CExpr -> CStatement

-- | a pattern definition
CSPat :: CPattern -> CExpr -> CStatement

-- | a local let declaration
CSLet :: [CLocalDecl] -> CStatement

-- | Pattern expressions.
data CPattern

-- | pattern variable (unique index / name)
CPVar :: CVarIName -> CPattern

-- | literal (Integer<i>Float</i>Char constant)
CPLit :: CLiteral -> CPattern

-- | application <tt>(m.c e1 ... en)</tt> of n-ary constructor <tt>m.c</tt>
--   (<tt>CPComb (m,c) [e1,...,en]</tt>)
CPComb :: QName -> [CPattern] -> CPattern

-- | as-pattern (extended Curry)
CPAs :: CVarIName -> CPattern -> CPattern

-- | functional pattern (extended Curry)
CPFuncComb :: QName -> [CPattern] -> CPattern

-- | lazy pattern (extended Curry)
CPLazy :: CPattern -> CPattern

-- | record pattern (extended curry)
CPRecord :: QName -> [CField CPattern] -> CPattern

-- | Literals occurring in an expression or a pattern, either an integer, a
--   float, a character, or a string constant. <i>Note:</i> The constructor
--   definition of <a>CIntc</a> differs from the original PAKCS definition.
--   It uses Haskell type <a>Integer</a> instead of <a>Int</a> to provide
--   an unlimited range of integer numbers. Furthermore, float values are
--   represented with Haskell type <a>Double</a> instead of <a>Float</a> to
--   gain double precision.
data CLiteral

-- | Int literal
CIntc :: Integer -> CLiteral

-- | Float literal
CFloatc :: Double -> CLiteral

-- | Char literal
CCharc :: Char -> CLiteral

-- | String literal
CStringc :: String -> CLiteral

-- | Labeled record fields
type CField a = (QName, a)

-- | Current version of AbstractCurry
version :: String
instance GHC.Show.Show Curry.AbstractCurry.Type.CurryProg
instance GHC.Read.Read Curry.AbstractCurry.Type.CurryProg
instance GHC.Classes.Eq Curry.AbstractCurry.Type.CurryProg
instance GHC.Show.Show Curry.AbstractCurry.Type.CRule
instance GHC.Read.Read Curry.AbstractCurry.Type.CRule
instance GHC.Classes.Eq Curry.AbstractCurry.Type.CRule
instance GHC.Show.Show Curry.AbstractCurry.Type.CFuncDecl
instance GHC.Read.Read Curry.AbstractCurry.Type.CFuncDecl
instance GHC.Classes.Eq Curry.AbstractCurry.Type.CFuncDecl
instance GHC.Show.Show Curry.AbstractCurry.Type.CRhs
instance GHC.Read.Read Curry.AbstractCurry.Type.CRhs
instance GHC.Classes.Eq Curry.AbstractCurry.Type.CRhs
instance GHC.Show.Show Curry.AbstractCurry.Type.CLocalDecl
instance GHC.Read.Read Curry.AbstractCurry.Type.CLocalDecl
instance GHC.Classes.Eq Curry.AbstractCurry.Type.CLocalDecl
instance GHC.Show.Show Curry.AbstractCurry.Type.CStatement
instance GHC.Read.Read Curry.AbstractCurry.Type.CStatement
instance GHC.Classes.Eq Curry.AbstractCurry.Type.CStatement
instance GHC.Show.Show Curry.AbstractCurry.Type.CExpr
instance GHC.Read.Read Curry.AbstractCurry.Type.CExpr
instance GHC.Classes.Eq Curry.AbstractCurry.Type.CExpr
instance GHC.Show.Show Curry.AbstractCurry.Type.CCaseType
instance GHC.Read.Read Curry.AbstractCurry.Type.CCaseType
instance GHC.Classes.Eq Curry.AbstractCurry.Type.CCaseType
instance GHC.Show.Show Curry.AbstractCurry.Type.CPattern
instance GHC.Read.Read Curry.AbstractCurry.Type.CPattern
instance GHC.Classes.Eq Curry.AbstractCurry.Type.CPattern
instance GHC.Show.Show Curry.AbstractCurry.Type.CLiteral
instance GHC.Read.Read Curry.AbstractCurry.Type.CLiteral
instance GHC.Classes.Eq Curry.AbstractCurry.Type.CLiteral
instance GHC.Show.Show Curry.AbstractCurry.Type.COpDecl
instance GHC.Read.Read Curry.AbstractCurry.Type.COpDecl
instance GHC.Classes.Eq Curry.AbstractCurry.Type.COpDecl
instance GHC.Show.Show Curry.AbstractCurry.Type.CFixity
instance GHC.Read.Read Curry.AbstractCurry.Type.CFixity
instance GHC.Classes.Eq Curry.AbstractCurry.Type.CFixity
instance GHC.Show.Show Curry.AbstractCurry.Type.CTypeDecl
instance GHC.Read.Read Curry.AbstractCurry.Type.CTypeDecl
instance GHC.Classes.Eq Curry.AbstractCurry.Type.CTypeDecl
instance GHC.Show.Show Curry.AbstractCurry.Type.CConsDecl
instance GHC.Read.Read Curry.AbstractCurry.Type.CConsDecl
instance GHC.Classes.Eq Curry.AbstractCurry.Type.CConsDecl
instance GHC.Show.Show Curry.AbstractCurry.Type.CFieldDecl
instance GHC.Read.Read Curry.AbstractCurry.Type.CFieldDecl
instance GHC.Classes.Eq Curry.AbstractCurry.Type.CFieldDecl
instance GHC.Show.Show Curry.AbstractCurry.Type.CTypeExpr
instance GHC.Read.Read Curry.AbstractCurry.Type.CTypeExpr
instance GHC.Classes.Eq Curry.AbstractCurry.Type.CTypeExpr
instance GHC.Show.Show Curry.AbstractCurry.Type.CVisibility
instance GHC.Read.Read Curry.AbstractCurry.Type.CVisibility
instance GHC.Classes.Eq Curry.AbstractCurry.Type.CVisibility


-- | This library contains I/O actions to read Curry programs and transform
--   them into this abstract representation as well as write them to a
--   file.
module Curry.AbstractCurry.Files

-- | Read an AbstractCurry file and return the corresponding AbstractCurry
--   program term of type <a>CurryProg</a>
readCurry :: FilePath -> IO (Maybe CurryProg)

-- | Write an AbstractCurry program term into a file.
writeCurry :: FilePath -> CurryProg -> IO ()

-- | Show an AbstractCurry program in a nicer way
showCurry :: CurryProg -> String


-- | This library contains a definition for representing Curry programs in
--   Haskell by the type <a>CurryProg</a> 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.
--   
--   <i>Assumption:</i> An AbstractCurry program <tt>Prog</tt> is stored in
--   a file with the file extension <tt>acy</tt>, i.e. in a file
--   <tt>Prog.acy</tt>.
module Curry.AbstractCurry
