How do I use a monoid instance of a function?

点点圈 提交于 2019-12-05 10:37:02

You're using this instance:

instance Monoid b => Monoid (a -> b) where
    mempty _ = mempty
    mappend f g x = f x `mappend` g x

which is more general because it doesn't require endomorphisms (i.e. a -> a). To get the instance you were expecting, you can wrap your functions in Endo:

appEndo (mconcat [Endo id, Endo id, Endo id, Endo id])

or

appEndo $ mconcat $ fmap Endo [id, id, id, id]
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!