tur/fix
stdlib/fix.tur
Fix type: the fixed-point of a functor, with cata and ana.
Since: Phase B1
defn
roll
(roll [layer :int])
wrap one layer of f into a Fix value.
Parameters
| layer | a value of type (f (Fix f)) |
Returns
A Fix value wrapping layer.
Example
(roll my-layer) ; => (Roll my-layer)
Since: Phase RF2
defn
unroll
(unroll [fix :int])
unwrap one layer of Fix to expose the inner functor value.
Parameters
| fix | a Fix value |
Returns
The inner f (Fix f) value.
Example
(unroll (roll x)) ; => x
Since: Phase RF2
defn
cata
(cata [alg :fn fix :int])
catamorphism: fold a Fix value using an F-algebra.
Parameters
| alg | a typed fat-closure (function from (f a) to a) stored as :fn | |
| fix | a Fix value to fold |
Returns
The result of applying alg to the unwrapped layer.
Example
(cata my-alg leaf-fix)
Since: Phase RF2
defn
ana
(ana [coalg :fn seed :int])
anamorphism: unfold a seed value into a Fix value using a co-algebra.
Parameters
| coalg | a typed fat-closure (function from a to (f a)) stored as :fn | |
| seed | the initial seed value |
Returns
A Fix value built by applying coalg to seed.
Example
(ana my-coalg seed-value)
Since: Phase RF2