plutarch
Safe HaskellNone
LanguageGHC2021

Plutarch.Internal.Fix

Synopsis

Documentation

pfixHoisted :: forall (s :: S) (a :: S -> Type) (b :: S -> Type). Term s (((a :--> b) :--> (a :--> b)) :--> (a :--> b)) Source #

Fixpoint recursion, used to encode recursive functions.

Note

This fixpoint combinator is hoisted, which allows for the smallest code size. However, in terms of execution units, pfixHoisted is the least efficient.

pfixHoisted used to be the default fixpoint combinator in Plutarch. If you used pfix before, and want to maintain identical behaviour, use this function.

Example

Additional examples can be found in examples/Recursion.hs.

iterateN' ::
 Term s (PInteger :--> (a :--> a) :--> a :--> a) ->
 Term s PInteger ->
 Term s (a :--> a) ->
 Term s a
iterateN' self n f x =
   pif (n #== 0)
       x
       (self # n - 1 #$ f x)

iterateN :: Term s (PInteger :--> (a :--> a) :--> a :--> a)
iterateN = pfixHoisted #$ plam iterateN'

Since: 1.12.0

pfix :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (Term s (a :--> b) -> Term s (a :--> b)) -> Term s (a :--> b) Source #

As pfixHoisted, but not hoisted. This is more efficient in terms of execution units, but takes up more script space.

Since: 1.12.0

pfixInline :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (Term s (a :--> b) -> Term s (a :--> b)) -> Term s (a :--> b) Source #

As pfix, but we perform some additional inlining into the function argument. This allows for even more speed, but at the cost of larger scripts.

Since: 1.12.0