在递归方案中,如何构造具有类型定义的内容,例如 (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)