2

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?

Dierk
  • 1,308
  • 7
  • 13

1 Answers1

2

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)

Ingo
  • 36,037
  • 5
  • 53
  • 100
  • I thought I had it but it needs more work. The latest state is in the repo. – Dierk Sep 14 '13 at 22:28
  • I compile with this [gradle build](https://gist.github.com/Dierk/6566983) It seems that the -sp flag does not work and one a) has to give _all_ files separately to the command line and b) has to care about the proper compile sequence manually. Is this by intention? – Dierk Sep 15 '13 at 00:30
  • 1
    The -sp flag is used only when the -make flag is given. In all other cases, the compiler uses only class files (on the classpath) or the file(s) on the command line (in the order given). Thus, in most cases it should be enough to say: `java -jar fregec.jar -d bin -make path/to/your/main/module/here.fr` – Ingo Sep 15 '13 at 08:55
  • 1
    I downloaded your sources, commented the assert function in FunctionApplication.fr and uncommented the util.Assertions import. Then the following command compiled the thing without problems: java -jar ~/frege/fregec.jar -v -d bin -make -sp Real_World_Frege-master/ Real_World_Frege-master/chapter2/FunctionApplication.fr – Ingo Sep 15 '13 at 09:20
  • It's cool to have asked late in the night and have the answer the next Sunday noon! Thanks for that. Much appreciated. The above works. It triggers the next question about how to compile a whole source tree, though, but I will ask separately. – Dierk Sep 15 '13 at 11:26
  • Yeah, no problem with that, Dierk. Today we have cold, foggy weather around here in the mountains where I am on vacation currently. – Ingo Sep 15 '13 at 11:30