free icon indicating copy to clipboard operation
free copied to clipboard

useful fold possibly

Open Icelandjack opened this issue 9 years ago • 2 comments

From "Monad transformers and modular algebraic effects: What binds them together"

fold :: Functor sig => (a -> b) -> (sig b -> b) -> (Free sig a -> b)
fold gen alg (Pure x) = gen x
fold gen alg (Free op) = alg (fmap (fold gen alg) op)

Icelandjack avatar Dec 22 '16 01:12 Icelandjack

fold f g is just a composition of fmap f and iter g right?

fumieval avatar Dec 22 '16 03:12 fumieval

It's fold gen alg = iter alg . fmap gen, probably not worth it but it makes generator / algebra explicit

Icelandjack avatar Dec 22 '16 03:12 Icelandjack