Module RW.Build

Some conversion, selection and building goodies

Author: Lasse Züngel

Summary of exported operations:

fromIndex0 :: [a] -> [Int]  Deterministic 
Generates a list [0,1,2,...] with the same length as the input list
fromIndex :: Int -> [a] -> [Int]  Deterministic 
Generates a list [i,i+1,i+2,...] with the same length as the input list
varName :: Int -> String  Deterministic 
Generates a var name for a given index
appendIf :: Bool -> [a] -> a -> [a]  Deterministic 
Appends an element to a list if a given condition is true
optimizeSingleConstructor :: [a] -> [b] -> [b]  Deterministic 
Removes the first element from a list if the first list's length is 1.
consArity :: CConsDecl -> Int  Deterministic 
Returns the amount of arguments of a given type constructor
consTypeExpressions :: CConsDecl -> [CTypeExpr]  Deterministic 
Returns the arguments (type expressions) of a given type constructor
isPolymorphic :: CTypeDecl -> Bool  Deterministic 
Returns true if the given type declaration is polymorphic (contains at least one type variable)
isMonomorphic :: CTypeDecl -> Bool  Deterministic 
Returns true if the given type declaration is monomorphic (contains no type variables)
typeVars :: CTypeDecl -> [(Int,String)]  Deterministic 
All type variables occurring in a given type declaration
unwrapApply :: CTypeExpr -> [CTypeExpr]  Deterministic 

Converts a recursive type expression to a sequence of type expressions

Example: unwrapApply (CTApply (CTApply (Cons "map") (Var "x")) (Var "y")) = [Cons "map", Var "x", Var "y"]

consVars :: CConsDecl -> [(Int,String)]  Deterministic 
All type variables occurring in a given constructor declaration
isTypeVar :: CTypeExpr -> Bool  Deterministic 
Returns true if the given type expression is a type variable
genericTypeVariable :: CTypeExpr  Deterministic 
The type variable used as the placeholder for instance declarations of the ReadWrite class
classConstraint :: String -> String -> [(Int,String)] -> [((String,String),CTypeExpr)]  Deterministic 
Generates the rwClass constraint for all type variables.
returnTypeExpr :: Bool -> CTypeExpr -> CTypeExpr -> CTypeExpr  Deterministic 
May or may not add the input type to the output.
combineWithR :: (String,String) -> [CExpr] -> CExpr  Deterministic 
Combines all given expressions with a given operator (right-associative)
combineWithL :: (String,String) -> [CExpr] -> CExpr  Deterministic 
Combines all given expressions with a given operator (left-associative)
concatExpr :: [CExpr] -> CExpr  Deterministic 
Concats all given expressions with the ++ operator
applyExpr :: [CExpr] -> CExpr  Deterministic 
Combines all given expressions with the .
equalsExpr :: CExpr -> CExpr -> CExpr  Deterministic 
Builds an expression 'e1 == e2'
otherwiseExpr :: CExpr  Deterministic 
otherwise, used for guards
returnExpr :: CExpr -> CStatement  Deterministic 
typeDeclToTypeExpr :: CTypeDecl -> CTypeExpr  Deterministic 
Converts a type decl data T t1 ...
typeDeclToName :: CTypeDecl -> String  Deterministic 
Converts a type decl data T t1 ...
isTypeSyn :: CTypeDecl -> Bool  Deterministic 
Returns true iff the given type declaration is a type synonym
showTypeExpr :: CTypeExpr -> String  Deterministic 
Simple pretty printer for type expressions
theCons :: (String,String) -> CTypeDecl -> CConsDecl  Deterministic 
Looks up an existing(!) constructor based on its name
anonPattern :: CPattern  Deterministic 
Anonymous pattern "_"
listRestPattern :: [CPattern] -> CPattern  Deterministic 
Constructs a head:rest-pattern from a list of patterns.
consToPolyPattern :: CConsDecl -> CPattern  Deterministic 
Pattern-matches the first occurrence of every type variable in a given type expression.
undefinedConstructorRule :: CConsDecl -> CRule  Deterministic 
Generates a useless rule.
instances :: CurryProg -> [CInstanceDecl]  Deterministic 
Returns the instance declarations of a curry program
instanceName :: CInstanceDecl -> (String,String)  Deterministic 
Returns the name of an instance declaration
flatProgToAbstract :: Prog -> CurryProg  Deterministic 
Converts a flatcurry program to an abstractcurry program.
whenJust :: Maybe a -> (a -> Bool) -> Bool  Deterministic 
auxiliary util functions If just a value is given, the predicate is applied to the value.
none :: (a -> Bool) -> [a] -> Bool  Deterministic 
not .
snd3 :: (a,b,c) -> b  Deterministic 
snd of a triple

Exported operations:

fromIndex0 :: [a] -> [Int]  Deterministic 

Generates a list [0,1,2,...] with the same length as the input list

fromIndex :: Int -> [a] -> [Int]  Deterministic 

Generates a list [i,i+1,i+2,...] with the same length as the input list

varName :: Int -> String  Deterministic 

Generates a var name for a given index

appendIf :: Bool -> [a] -> a -> [a]  Deterministic 

Appends an element to a list if a given condition is true

Further infos:
  • solution complete, i.e., able to compute all solutions

optimizeSingleConstructor :: [a] -> [b] -> [b]  Deterministic 

Removes the first element from a list if the first list's length is 1. Otherwise, the list is returned unchanged.

consArity :: CConsDecl -> Int  Deterministic 

Returns the amount of arguments of a given type constructor

consTypeExpressions :: CConsDecl -> [CTypeExpr]  Deterministic 

Returns the arguments (type expressions) of a given type constructor

isPolymorphic :: CTypeDecl -> Bool  Deterministic 

Returns true if the given type declaration is polymorphic (contains at least one type variable)

isMonomorphic :: CTypeDecl -> Bool  Deterministic 

Returns true if the given type declaration is monomorphic (contains no type variables)

typeVars :: CTypeDecl -> [(Int,String)]  Deterministic 

All type variables occurring in a given type declaration

Further infos:
  • solution complete, i.e., able to compute all solutions

unwrapApply :: CTypeExpr -> [CTypeExpr]  Deterministic 

Converts a recursive type expression to a sequence of type expressions

Example: unwrapApply (CTApply (CTApply (Cons "map") (Var "x")) (Var "y")) = [Cons "map", Var "x", Var "y"]

consVars :: CConsDecl -> [(Int,String)]  Deterministic 

All type variables occurring in a given constructor declaration

isTypeVar :: CTypeExpr -> Bool  Deterministic 

Returns true if the given type expression is a type variable

genericTypeVariable :: CTypeExpr  Deterministic 

The type variable used as the placeholder for instance declarations of the ReadWrite class

Further infos:
  • solution complete, i.e., able to compute all solutions

classConstraint :: String -> String -> [(Int,String)] -> [((String,String),CTypeExpr)]  Deterministic 

Generates the rwClass constraint for all type variables. Given a type data T t1 ... tn = ... This function can be used to derive all constraints necessary to generate the instance header instance (ReadWrite t1, ..., ReadWrite tn) => ReadWrite (T t1 ... tn)

returnTypeExpr :: Bool -> CTypeExpr -> CTypeExpr -> CTypeExpr  Deterministic 

May or may not add the input type to the output. For a given call > returnTypeExpr r a b If r is true, then the resulting type expression is fun :: b -> (a, b) Otherwise, the resulting expression is fun :: b -> a

This is useful when building type expressions for the read function.

Further infos:
  • solution complete, i.e., able to compute all solutions

combineWithR :: (String,String) -> [CExpr] -> CExpr  Deterministic 

Combines all given expressions with a given operator (right-associative)

combineWithL :: (String,String) -> [CExpr] -> CExpr  Deterministic 

Combines all given expressions with a given operator (left-associative)

concatExpr :: [CExpr] -> CExpr  Deterministic 

Concats all given expressions with the ++ operator

applyExpr :: [CExpr] -> CExpr  Deterministic 

Combines all given expressions with the . operator

equalsExpr :: CExpr -> CExpr -> CExpr  Deterministic 

Builds an expression 'e1 == e2'

otherwiseExpr :: CExpr  Deterministic 

otherwise, used for guards

returnExpr :: CExpr -> CStatement  Deterministic 

Further infos:
  • solution complete, i.e., able to compute all solutions

typeDeclToTypeExpr :: CTypeDecl -> CTypeExpr  Deterministic 

Converts a type decl data T t1 ... tn = ... to a type expression T1 t1 ... tn

typeDeclToName :: CTypeDecl -> String  Deterministic 

Converts a type decl data T t1 ... tn = ... to a string T

isTypeSyn :: CTypeDecl -> Bool  Deterministic 

Returns true iff the given type declaration is a type synonym

showTypeExpr :: CTypeExpr -> String  Deterministic 

Simple pretty printer for type expressions

Further infos:
  • solution complete, i.e., able to compute all solutions

theCons :: (String,String) -> CTypeDecl -> CConsDecl  Deterministic 

Looks up an existing(!) constructor based on its name

anonPattern :: CPattern  Deterministic 

Anonymous pattern "_"

Further infos:
  • solution complete, i.e., able to compute all solutions

listRestPattern :: [CPattern] -> CPattern  Deterministic 

Constructs a head:rest-pattern from a list of patterns. For n passed patterns, the resulting pattern is p1:p2:...:pn If the list is empty, the resulting pattern is []

consToPolyPattern :: CConsDecl -> CPattern  Deterministic 

Pattern-matches the first occurrence of every type variable in a given type expression.

For a specific constructor of a type definition data T t1 ... tn = ... | C e1 ... em | ... this function generates a pattern C p1 ... pm where pi (1 <= i <= m) is...

  • a variable ei' if ei the first occurence of a polymorphic type variable t1 ... tn in the constructor
  • a wildcard _ otherwise

Example: data T a = C a String a [a] consToPolyPattern C -> C a' _

undefinedConstructorRule :: CConsDecl -> CRule  Deterministic 

Generates a useless rule.

instances :: CurryProg -> [CInstanceDecl]  Deterministic 

Returns the instance declarations of a curry program

Further infos:
  • solution complete, i.e., able to compute all solutions

instanceName :: CInstanceDecl -> (String,String)  Deterministic 

Returns the name of an instance declaration

Further infos:
  • solution complete, i.e., able to compute all solutions

flatProgToAbstract :: Prog -> CurryProg  Deterministic 

Converts a flatcurry program to an abstractcurry program. Extracts only the name, imports and type definitions.

Converts FCY type synonyms to ACT data declarations.

Naming scheme for type variables of polymorphic type definitions: data T a ... z a1 ... z1 ... = ...

whenJust :: Maybe a -> (a -> Bool) -> Bool  Deterministic 

auxiliary util functions If just a value is given, the predicate is applied to the value. Otherwise, false is returned.

none :: (a -> Bool) -> [a] -> Bool  Deterministic 

not . any

snd3 :: (a,b,c) -> b  Deterministic 

snd of a triple

Further infos:
  • solution complete, i.e., able to compute all solutions