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
booltype, this returns the type object forPrelude.Bool.
- curry.interpreter.conversions.getconverter(converter)[source]
Get the converter corresponding to the argument:
Noneand a callable are returned as they are,'topython'namestopython(), 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,_band 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, andtuple. 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.evalpasses the type of the goal it built.
- Raises:
NotConstructorError – Non-ground data was encountered along a list spine.
- Returns:
The value converted to Python.