curry.interpreter.conversions module

Functions for working with Curry expresions. Handles conversions between Curry and Python.

curry.interpreter.conversions.currytype(interp, ty)[source]

Gets the Curry type corresponding to a Python type. For instance, for the Python bool type, this returns the type object for Prelude.Bool.

curry.interpreter.conversions.getconverter(converter)[source]

Get the converter corresponding to the argument: None and a callable are returned as they are, 'topython' names topython(), and any other name means no conversion. A free variable in a value passes through the converter as a node; curry.show_value() prints it as _a, _b and so on.

curry.interpreter.conversions.topython(value, convert_strings=True, exprtype=None)[source]

Converts a Curry value to Python by substituting built-in types.

This functions converts (recursively) the types int, float, str, bool, list, and tuple. Other types are passed through untouched.

Parameters:
  • value – The Curry value to convert.

  • convert_strings – If True, then lists of characters are converted to Python strings.

  • exprtype – The static type of the value, in Curry syntax or as a FlatCurry type, or None. The type is threaded through the lists and the tuples: an empty list under [Char] converts to '', while a list under a type variable or without a type converts to a string when it holds characters. curry.eval passes the type of the goal it built.

Raises:

NotConstructorError – Non-ground data was encountered along a list spine.

Returns:

The value converted to Python.

curry.interpreter.conversions.unbox(arg)[source]

Unbox a built-in primitive or IO type.