“Return 类型不兼容”/应用实例上的错误本机声明模块错误
“Return type is incompatible” / Bad native declaration module error on applicative instance
我正在阅读 Christopher Allen 和 Julie Moronuki 合着的书 "Haskell Programming from first principles",并尝试在 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 中尝试了相同的代码,但没有出现任何错误。
使用 "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
(我刚刚尝试了 "Three" 示例,编译成功)
我正在阅读 Christopher Allen 和 Julie Moronuki 合着的书 "Haskell Programming from first principles",并尝试在 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 中尝试了相同的代码,但没有出现任何错误。
使用 "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
(我刚刚尝试了 "Three" 示例,编译成功)