curry.backends.py.graph.utility module

curry.backends.py.graph.utility.copy_spine(root, realpath, end=None, rewrite=None)[source]

Copies the spine from root along realpath.

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=f would overwrite f rather 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 f shall be applied to.

  • fapply – A keyword-only argument indicating which function to use for applications. By default, Prelude.apply is 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

  1. curry(f, a, b) returns the expression apply(apply(f, a), b).

  2. curry(prelude.Nil) creates the empty list.

  3. curry(prelude.Cons) creates the partial application (:); i.e., the list constructor applied to no arguments.

  4. curry(prelude.Cons, 1) creates the partial list (1:). ; i.e., the list constructor applied to 1.

  5. curry(f, a, fapply='$##') returns the expression f $## a.

curry.backends.py.graph.utility.joinpath(*parts)[source]

Join expression paths. Each part should be None, an Integer, or an iterable. All will be chained together. Returns a list of integers containing the joined path..

curry.backends.py.graph.utility.rewrite(rts, target, info, *args, **kwds)[source]
curry.backends.py.graph.utility.shallow_copy(node)[source]