Library to annotate the expressions of a FlatCurry program with type information.
It can be used by any other Curry program which processes or transforms FlatCurry programs. The main operation to use is
inferProg :: Prog -> IO (Either String (AProg TypeExpr))
which annotates a FlatCurry program with type information.
The type inference works in several steps:
In addition, the function inferNewFunctions
allows to infer the types
of a list of functions whose type is not known before. Consequently,
this disallows polymorphic recursive functions. Those functions are
separated into strongly connected components before their types are inferred
to allow mutually recursive function definitions.
In case of any error, the type inference quits with an error message.
IMPORTANT NOTE: The type inference is incomplete w.r.t. type classes and forall types. This need to be extended in the future!
Author: Jonas Oberschweiber, Bjoern Peemoeller, Michael Hanus
Version: December 2020
inferProg
:: Prog -> IO (Either String (AProg TypeExpr))
Infers the type of a whole program. |
inferProgFromProgEnv
:: [(String,Prog)] -> Prog -> Either String (AProg TypeExpr)
Infers the type of a whole program w.r.t. |
inferFunction
:: Prog -> (String,String) -> IO (Either String (AFuncDecl TypeExpr))
Infers the types of a single function specified by its qualified name. |
inferNewFunctions
:: Prog -> [FuncDecl] -> IO (Either String [AFuncDecl TypeExpr])
Infers the types of a group of (possibly mutually recursive) functions. |
inferExpr
:: Prog -> Expr -> IO (Either String (AExpr TypeExpr))
Infer the type of a single expression. |
inferProgEnv
:: Map (String,String) TypeExpr -> Prog -> Either String (AProg TypeExpr)
Infers the type of a whole program. |
inferFunctionEnv
:: Map (String,String) TypeExpr -> Prog -> (String,String) -> Either String (AFuncDecl TypeExpr)
Infers the types of a single function specified by its qualified name. |
inferNewFunctionsEnv
:: Map (String,String) TypeExpr -> String -> [FuncDecl] -> Either String [AFuncDecl TypeExpr]
Infers the types of a group of (possibly mutually recursive) functions. |
inferExprEnv
:: Map (String,String) TypeExpr -> Expr -> Either String (AExpr TypeExpr)
Infers the types of a single expression. |
getTypeEnv
:: Prog -> IO (Map (String,String) TypeExpr)
Extract the type environment from the given Prog. |
getTypeEnvFromProgEnv
:: [(String,Prog)] -> Prog -> Either String (Map (String,String) TypeExpr)
Extract the type environment from the given Prog by lookup in a module name -> Prog environment. |
A type environment.
Type synonym: TypeEnv = Map QName TypeExpr
Infers the type of a whole program.
|
Infers the type of a whole program w.r.t. a list of imported modules.
|
Infers the types of a single function specified by its qualified name.
|
Infers the types of a group of (possibly mutually recursive) functions. Note that the functions are only monomorphically instantiated, i.e., polymorphic recursion is not supported. The given type may be too general, for instance a type variable only, and will be specialised to the inferred type. |
Infer the type of a single expression.
|
Infers the type of a whole program. Uses the given type environment instead of generating a new one.
|
Infers the types of a single function specified by its qualified name. Uses the given type environment instead of generating a new one.
|
Infers the types of a group of (possibly mutually recursive) functions. Note that the functions are only monomorphically instantiated, i.e., polymorphic recursion is not supported. The given type may be too general, for instance a type variable only, and will be specialised to the inferred type. |
Infers the types of a single expression. Uses the given type environment instead of generating a new one.
|
Extract the type environment from the given Prog.
|
Extract the type environment from the given Prog by lookup in a module name -> Prog environment.
|