2

为了自检示例,我运行了以下代码:

assert :: Bool -> Bool -> String -> IO ()
assert actual expected description
    | expected == actual     = do { print "" }   -- need a better way to do nothing
    | otherwise              = error description

main _ = do
    assert (odd 2) false "2 is not odd"
    assert (odd 3) true  "3 is odd"

我知道这并不完美(建议非常受欢迎),但当前的问题是,当我将断言的定义放入模块 util.Assertions 时,使用两个断言无法编译

build/realworld/chapter2/FunctionApplication.java:168: error: cannot access ?
              Assertions.?._assert?.apply(
                        ^
class file for util.Assertions$? not found
1 error
E .../Real_World_Frege/chapter2/FunctionApplication.fr:24: java compiler errors are most likely caused by erronous
native definitions

它在我只有一个断言时起作用,因此类本身在 CP 上,并且模块导入原则上起作用。怎么了?

4

1 回答 1

2

您的assert函数会产生一种形式的类型m ()where mis a Monad。因此,“什么都不做”的最好方法就是

return ()

对于你问题的第二部分,我真的无法想象出了什么问题。请安排您的 github 存储库,以便我可以下载并自己尝试。另外,给出你使用的编译命令和工作目录。

(顺便说一句,你应该使用可以显示Unicode的终端模拟器。在Windows下,试试chcp 65001

于 2013-09-13T17:47:33.077 回答