我正在阅读这篇出色的论文“结构化图的函数式编程,Bruno C. d. S. Oliveira”(这里有一些视频),并且我正在尝试实现所有的结构。我正在努力使用存在主义。尽管作者提到了 Haskell throghout,但似乎这些类型在 Coq 或 Agda 中更容易表达。我怎样才能使这个编译?谢谢。
代码
data PStream a v = Var v
| Mu (v -> PStream a v)
| Cons a (PStream a v)
data Stream a = forall v. Pack {pop :: PStream a v}
foldStream :: (a -> b -> b) -> b -> Stream a -> b
foldStream f k (Pack s) = pfoldStream s
where pfoldStream (Var x) = x
pfoldStream (Mu g) = pfoldStream (g k)
pfoldStream (Cons x xs) = f x (pfoldStream xs)
错误
error:
Couldn't match type `v' with `b'
`v' is a rigid type variable bound by
a pattern with constructor
Pack :: forall a v. PStream a v -> Stream a,
in an equation for `foldStream'
at C:\...\StructuredGraph.hs:17:17
`b' is a rigid type variable bound by
the type signature for
foldStream :: (a -> b -> b) -> b -> Stream a -> b
at C:\...\StructuredGraph.hs:17:1
Expected type: PStream a b
Actual type: PStream a v
In the first argument of `pfoldStream', namely `s'
In the expression: pfoldStream s