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 CurryModule objects. 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: Num to Int, Fractional to Float, Monad to IO, a lone Data to Bool; see curry.typecheck.defaulting.

  • modulename – Specifies the module name. Used only in ‘module’ mode. The module is placed in curry.interpreter:Interpreter.modules under 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 in where x, y free declares free variables, as in the REPL. A variable whose type is absent from the result type of the expression cannot show in a value, so curry.eval yields 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. With exprtype, or with a comment after free, 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 :type prints in the REPL. A trailing where x free stays a local declaration, as in the :type of PAKCS.