What was wrong with Control.MonadPlus.Free?

后端 未结 2 1079
刺人心
刺人心 2021-01-17 10:51

The free MonadPlus defined as

data Free f a = Pure a | Free (f (Free f a)) | Plus [Free f a]

was removed in free 4.6 with the foll

2条回答
  •  感情败类
    2021-01-17 11:48

    I believe that the representation itself was OK and that the lawfulness could have been remedied by changing these method signatures

    iter :: Functor f => (f a -> a) -> ([a] -> a) -> Free f a -> a
    iterM :: (Monad m, Functor f) => (f (m a) -> m a) -> ([m a] -> m a) -> Free f a -> m a
    

    to

    iter :: (Functor f, Monoid a) => (f a -> a) -> Free f a -> a
    iterM :: (MonadPlus m, Functor f) => (f (m a) -> m a) -> Free f a -> m a
    

    i.e.

    • use Monoid a instead of an arbitrary function [a] -> a in iter;
    • use MonadPlus m instead of an arbitrary function [m a] -> m a in iterM.

    My guess is that it was removed (instead of fixed) just because it is not worth to keep around when FreeT f [] gives an equivalent representation.

提交回复
热议问题