curry.backends.py.graph.utility module
- curry.backends.py.graph.utility.copy_spine(root, realpath, end=None, rewrite=None)[source]
Copies the spine from
rootalongrealpath.- Parameters:
root – The node at which to begin.
realpath – The real path along which to copy.
end – The expression to place at the end of the copied spine.
rewrite – A node to rewrite with the result.
- Returns:
The root of the copied expression.
Example
The following command could perform the transformation shown after:
>>> copy_spine(root=f, path=[1,0], end=u)
f f' / | \ ----> / | \ A B C A B' C | | ? u / \ u v
Supplying
rewrite=fwould overwritefrather than create a new node,f'.
- curry.backends.py.graph.utility.curry(rts, f, *args, **kwds)[source]
Curries a function with a list of arguments.
- Parameters:
f – The expression to apply. If this is a Node, it is simply used. Otherwise, it must have an ‘info’ attribute with information about a function or constructor node. That will be used to create a partial application object or expression, in the case of a nullary symbol.
args – The arguments that
fshall be applied to.fapply – A keyword-only argument indicating which function to use for applications. By default,
Prelude.applyis used. If a string is provided, it is used to look up a symbol in the Prelude. Otherwise, the supplied argument should be node info.
- Returns:
A Curry expression.
Examples
curry(f, a, b)returns the expressionapply(apply(f, a), b).curry(prelude.Nil)creates the empty list.curry(prelude.Cons)creates the partial application(:); i.e., the list constructor applied to no arguments.curry(prelude.Cons, 1)creates the partial list(1:). ; i.e., the list constructor applied to 1.curry(f, a, fapply='$##')returns the expressionf $## a.