小编Zhu*_*uan的帖子

如何使用递归方案更新结构?

在递归方案中,如何构造具有类型定义的内容,例如 (Recursive t, CoRecursive t) -> t -> ? -> t

我尝试使用递归方案来更新节点。以列表为例,我可以想到两种方法:

update :: [a] -> Natural -> a -> [a]
update = para palg where
  palg Nil _ _ = []
  palg (Cons a (u, _)) 0 b = b : u
  palg (Cons a (u, f)) n b = a : f (n-1) b

update' :: [a] -> Natural -> a -> [a]
update' = c2 (apo acoalg) where
  c2 f a b c = f (a,b,c)
  acoalg …
Run Code Online (Sandbox Code Playgroud)

haskell recursion-schemes

6
推荐指数
1
解决办法
114
查看次数

标签 统计

haskell ×1

recursion-schemes ×1