作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个输出值列表的箭头( a b [c]
)和另一个接受该类型的单个值的箭头( a c d
)。我需要的基本上是一种将它们链接起来或将第二个箭头提升到 a [c] [d]
的方法。 .
最佳答案
你不能只用 Arrow
类型类。起重 a b c
进入 a [b] [c]
需要在 []
之间进行选择和 (:)
案子。幸运的是,ArrowChoice
正好提供这种操作。
mapA :: ArrowChoice a => a b c -> a [b] [c]
mapA f = proc list -> case list of
[] -> returnA -< []
x:xs -> do
y <- f -< x
ys <- mapA f -< xs
returnA -< y:ys
chain :: ArrowChoice a => a b [c] -> a c d -> a b [d]
chain f g = f >>> mapA g
proc
表示法,我们需要一个将列表构造函数转换为
Either
的函数:
listCase :: [a] -> Either () (a, [a])
listCase [] = Left ()
listCase (x:xs) = Right (x,xs)
mapA f = arr listCase >>>
arr (const []) ||| (f *** mapA f >>> arr (uncurry (:)))
关于haskell - 链接类型为 `a b [c]` 和 `a c d` 的箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13665879/
我是一名优秀的程序员,十分优秀!