Arrow equivalent of mapM?

给你一囗甜甜゛ 提交于 2019-12-03 23:39:07

You can't without choice. The lifting function will have this type:

mapA :: (ArrowChoice a) => a b c -> a [b] [c]

The easiest way to implement is by using proc notation:

mapA c =
    proc xs' ->
        case xs' of
            [] -> returnA -< []
            (x:xs) -> uncurry (:) ^<< c *** mapA c -< (x, xs)

Untested code, but should work. Note however that a function that generic is going to be really slow. I recommend writing this mapping function for your arrow specifically.

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