| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Plutarch.Internal.Fix
Synopsis
- pfixHoisted :: forall (s :: S) (a :: S -> Type) (b :: S -> Type). Term s (((a :--> b) :--> (a :--> b)) :--> (a :--> b))
- pfix :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (Term s (a :--> b) -> Term s (a :--> b)) -> Term s (a :--> b)
- pfixInline :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (Term s (a :--> b) -> Term s (a :--> b)) -> Term s (a :--> b)
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