Haskell语言学习笔记(72)Free Monad

Free Monad

data Free f a = Pure a | Free (f (Free f a))

instance Functor f => Monad (Free f) where
  return = Pure
  Free x >>= f = Free (fmap (>>= f) x)
  Pure x >>= f = f x

参考链接

https://github.com/lotz84/haskell/blob/master/docs/free-monad.md

猜你喜欢

转载自www.cnblogs.com/zwvista/p/9213331.html