Some conversion, selection and building goodies
Author: Lasse Züngel
fromIndex0
:: [a] -> [Int]
Generates a list [0,1,2,...] with the same length as the input list |
fromIndex
:: Int -> [a] -> [Int]
Generates a list [i,i+1,i+2,...] with the same length as the input list |
varName
:: Int -> String
Generates a var name for a given index |
appendIf
:: Bool -> [a] -> a -> [a]
Appends an element to a list if a given condition is true |
optimizeSingleConstructor
:: [a] -> [b] -> [b]
Removes the first element from a list if the first list's length is 1. |
consArity
:: CConsDecl -> Int
Returns the amount of arguments of a given type constructor |
consTypeExpressions
:: CConsDecl -> [CTypeExpr]
Returns the arguments (type expressions) of a given type constructor |
isPolymorphic
:: CTypeDecl -> Bool
Returns true if the given type declaration is polymorphic (contains at least one type variable) |
isMonomorphic
:: CTypeDecl -> Bool
Returns true if the given type declaration is monomorphic (contains no type variables) |
typeVars
:: CTypeDecl -> [(Int,String)]
All type variables occurring in a given type declaration |
unwrapApply
:: CTypeExpr -> [CTypeExpr]
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)]
All type variables occurring in a given constructor declaration |
isTypeVar
:: CTypeExpr -> Bool
Returns true if the given type expression is a type variable |
genericTypeVariable
:: CTypeExpr
The type variable used as the placeholder for instance declarations of the ReadWrite class |
genericTypeVariableName
:: (Int,String)
|
classConstraint
:: String -> String -> [(Int,String)] -> [((String,String),[CTypeExpr])]
Generates the rwClass constraint for all type variables. |
returnTypeExpr
:: Bool -> CTypeExpr -> CTypeExpr -> CTypeExpr
May or may not add the input type to the output. |
combineWithR
:: (String,String) -> [CExpr] -> CExpr
Combines all given expressions with a given operator (right-associative) |
combineWithL
:: (String,String) -> [CExpr] -> CExpr
Combines all given expressions with a given operator (left-associative) |
concatExpr
:: [CExpr] -> CExpr
Concats all given expressions with the ++ operator |
applyExpr
:: [CExpr] -> CExpr
Combines all given expressions with the . |
equalsExpr
:: CExpr -> CExpr -> CExpr
Builds an expression 'e1 == e2' |
otherwiseExpr
:: CExpr
otherwise, used for guards |
returnExpr
:: CExpr -> CStatement
|
typeDeclToTypeExpr
:: CTypeDecl -> CTypeExpr
Converts a type decl data T t1 ... |
typeDeclToName
:: CTypeDecl -> String
Converts a type decl data T t1 ... |
isTypeSyn
:: CTypeDecl -> Bool
Returns true iff the given type declaration is a type synonym |
showTypeExpr
:: CTypeExpr -> String
Simple pretty printer for type expressions |
theCons
:: (String,String) -> CTypeDecl -> CConsDecl
Looks up an existing(!) constructor based on its name |
anonPattern
:: CPattern
Anonymous pattern "_" |
listRestPattern
:: [CPattern] -> CPattern
Constructs a head:rest-pattern from a list of patterns. |
consToPolyPattern
:: CConsDecl -> CPattern
Pattern-matches the first occurrence of every type variable in a given type expression. |
undefinedConstructorRule
:: CConsDecl -> CRule
Generates a useless rule. |
instances
:: CurryProg -> [CInstanceDecl]
Returns the instance declarations of a curry program |
instanceName
:: CInstanceDecl -> (String,String)
Returns the name of an instance declaration |
flatProgToAbstract
:: Prog -> CurryProg
Converts a flatcurry program to an abstractcurry program. |
whenJust
:: Maybe a -> (a -> Bool) -> Bool
auxiliary util functions If just a value is given, the predicate is applied to the value. |
none
:: (a -> Bool) -> [a] -> Bool
not . |
snd3
:: (a,b,c) -> b
snd of a triple |
Generates a list [0,1,2,...] with the same length as the input list |
Generates a list [i,i+1,i+2,...] with the same length as the input list |
Generates a var name for a given index
|
Appends an element to a list if a given condition is true
|
Removes the first element from a list if the first list's length is 1. Otherwise, the list is returned unchanged. |
Returns the arguments (type expressions) of a given type constructor |
Returns true if the given type declaration is polymorphic (contains at least one type variable)
|
Returns true if the given type declaration is monomorphic (contains no type variables) |
All type variables occurring in a given type declaration
|
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"] |
All type variables occurring in a given constructor declaration
|
The type variable used as the placeholder for instance declarations of the ReadWrite class
|
|
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) |
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.
|
Combines all given expressions with a given operator (right-associative) |
Combines all given expressions with a given operator (left-associative) |
Concats all given expressions with the ++ operator |
Builds an expression 'e1 == e2' |
otherwise, used for guards |
|
Converts a type decl data T t1 ... tn = ... to a type expression T1 t1 ... tn
|
Converts a type decl data T t1 ... tn = ... to a string T
|
Simple pretty printer for type expressions
|
Looks up an existing(!) constructor based on its name |
Anonymous pattern "_"
|
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 [] |
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...
Example: data T a = C a String a [a] consToPolyPattern C -> C a' _
|
Generates a useless rule. |
Returns the instance declarations of a curry program
|
Returns the name of an instance declaration
|
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 ... = ... |
auxiliary util functions If just a value is given, the predicate is applied to the value. Otherwise, false is returned. |
not . any |
snd of a triple
|