curry.toolchain.flat2icurry.elimnewtype module

Newtype elimination, the first pass. It follows FlatCurry.ElimNewtype of the Curry package flatcurry.

For a declaration newtype T a = C te:

  • The declaration becomes a data declaration with one unary constructor.

  • A type T t becomes te with a replaced by t. Operations named _inst#... keep their types.

  • A constructor application C e becomes e.

  • A partial application C becomes the partial Prelude.id.

  • A case case x of C y -> e becomes e with y replaced by x, or a Let when the scrutinee is not a variable.

The newtypes come from the module and from the interfaces of its imports.

curry.toolchain.flat2icurry.elimnewtype.elim_newtype(impprogs, prog)[source]

Eliminates the newtypes of prog. impprogs are its imports.

curry.toolchain.flat2icurry.elimnewtype.newtypes_of(typedecls)[source]

Maps the name of each newtype to (typevars, consname, typeexpr). The first declaration of a name wins, as the Curry lookup does.

curry.toolchain.flat2icurry.elimnewtype.subst_var(x, y, e0)[source]

Replaces the variable x by the variable y in an expression. The walk runs on a stack of its own (utility.trampoline.trampoline()).