ekmett / free

free monads
http://hackage.haskell.org/package/free
Other
161 stars 65 forks source link

useful fold possibly #145

Open Icelandjack opened 7 years ago

Icelandjack commented 7 years ago

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)
fumieval commented 7 years ago

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

Icelandjack commented 7 years ago

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