how to use multiple inline assertions in Frege

75 views Asked by At

for the sake of self-checking examples, I got the following code running:

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"

I know this is not perfect (and advice is more than welcome) but the current issue is that when I put the definition of assert into a module util.Assertions then using two assertions fails to compile with

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

It works when I have only one assertion, so the class itself is on the CP and the module import works in principle. What is wrong?

1

There are 1 answers

6
Ingo On BEST ANSWER

Your assert function results in a type of the form m () where m is a Monad. The best way to "do nothing" is therefore to just

return ()

For the second part of your question I can not really imagine what is wrong. Please arrange your github repo so that I could download it and try for myself. Also, give the compile command you use and the working directory.

(Btw, you should use a terminal emulator that can display Unicode. Under Windows, try chcp 65001)