我正在阅读克里斯托弗·艾伦(Christopher Allen)和朱莉·莫洛诺基(Julie Moronuki)的《从第一原理开始的Haskell编程》一书,并尝试在Frege中实现代码和示例。
不幸的是,我在下面的代码(第17章-应用;本章练习)的模块级别(在eclipse编辑器中)遇到编译错误。
错误指出以下内容:
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中尝试了相同的代码,但没有出错。
使用“未定义”关键字来减少代码并不能解决问题,因此实例本身的结构似乎还存在其他问题。
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中正确编译。 (请参阅上面的回购)
有人可以给我提示这里有什么问题以及如何解决吗?
非常感谢。
答案 0 :(得分:0)
您必须使用过时的Frege编译器。
我建议您在这里获得最新的编译器:https://github.com/Frege/frege/releases/tag/3.25alpha
(我刚刚尝试了“ Three”示例,并且编译成功)