"返回类型不兼容"/应用实例上的本机声明模块错误



>我正在阅读Christopher Allen和Julie Moronuki的"Haskell Programming from First principles"一书,并尝试在Frege中实现代码和示例。

不幸的是,我在模块级别(在 eclipse 编辑器中)遇到了以下代码的编译错误(第 17 章 - 应用;章节练习)。

该错误指出如下:

Multiple messages at this line. -The return type is incompatible with PreludeMonad.CApplicative<Exercises17.TThree<a,b,? >>.ƒpure(Lazy<b>) -Java compiler errors are almost always caused by bad native declarations. When you're sure this is out of the question you've found a compiler bug, please report under https://github.com/frege/frege/issues and attach a copy of /Users/dkm/frege-workspace/frege_programming/bin/chapter17/Exercises17.java -The parameterized method <b, a, b>pure(Monoid.CMonoid<a>, Monoid.CMonoid<b>, Lazy<b>) of type Exercises17.IApplicative_Three is not applicable for the arguments (Monoid.CMonoid<a>, Monoid.CMonoid<b>, Lazy<b>)

我在 Haskell 中尝试了相同的代码,在那里我没有收到任何错误。

使用"undefined"关键字减少代码并不能解决问题,因此实例本身的结构似乎还存在其他问题。

data Three a b c = Three a b c
instance Functor (Three a b) where
fmap f (Three x y z) = Three x y (f z)
instance (Monoid a, Monoid b) => Applicative (Three a b) where
pure x = undefined
(Three a b f) <*> (Three c d x) = undefined

您也可以在此处找到上述代码和其他类似的(失败以及正确编译)示例: https://github.com/elrocqe/frege_programming/blob/15e3bc5c4748055dc7dc640677faa54d8e9539e3/src/chapter17/Exercises17.fr#L80

我要找的应用实例最终应该看起来像这样:

instance (Monoid a, Monoid b) => Applicative (Three a b) where
pure x = Three mempty mempty x
(Three a b f) <*> (Three c d x) = (Three (mappend a c) (mappend b d) (f x))

由于它在 Haskell 中工作,预期的结果是它也在 Frege 中编译。类似的示例在 Frege 中也可以正确编译。(见上面的回购)

任何人都可以给我一个提示,说明这里有什么问题以及如何解决它?

提前非常感谢。

您必须使用的是过时的 Frege 编译器。

我建议你在这里获取最新的编译器:https://github.com/Frege/frege/releases/tag/3.25alpha

(我刚刚尝试了"三"示例,编译正常)

相关内容

最新更新