curry.interpreter.compile module
Implements Interpreter.compile.
- curry.interpreter.compile.compile(string, mode='module', imports=None, exprtype=None, modulename=None)[source]
Compile a string containing Curry code. In mode ‘module’, the string is interpreted as a Curry module. In mode ‘expr’, the string is interpreted as a Curry expression.
- Parameters:
string – A string containing Curry code.
mode – Indicates how to interpret the string (see above).
imports – A list specifying additional modules to import. The elements can be strings or
CurryModuleobjects. Import statements will be prepended to the code string and CURRYPATH will be adjusted accordingly. This can be useful when importing dynamically-compiled modules whose names and locations are difficult to obtain.exprtype – A string specifying the expression type. This is what would appear to the right of
::in a Curry type annotation for the expression. Used only in ‘expr’ mode. Without it, the class constraints of the expression are defaulted with the table of the PAKCS REPL:NumtoInt,FractionaltoFloat,MonadtoIO, a loneDatatoBool; seecurry.typecheck.defaulting.modulename – Specifies the module name. Used only in ‘module’ mode. The module is placed in
curry.interpreter:Interpreter.modulesunder that name. By default, a unique name is chosen, which no later compile reuses.
- Returns:
In ‘module’ mode, a
CurryModule. In ‘expr’ mode, a Curry expression. A text that ends inwhere x, y freedeclares free variables, as in the REPL. A variable whose type is absent from the result type of the expression cannot show in a value, socurry.evalyields each value of such an expression with its binding (Bindings); a variable whose type occurs in the result type is left in the value. The REPL of PAKCS prints the binding of every declared variable. Withexprtype, or with a comment afterfree, the clause stays a local declaration and no binding is reported.- Raises:
CompileError – The front end rejects the text, or, in ‘expr’ mode without
exprtype, the table cannot default a class constraint.
- curry.interpreter.compile.expression_scheme(interp, string, imports=None)[source]
The type scheme of a Curry expression, as the front end infers it for the binding
compiled_expression = <string>, before any defaulting; what:typeprints in the REPL. A trailingwhere x freestays a local declaration, as in the:typeof PAKCS.