flix / book

The Flix Programming Book
Other
14 stars 22 forks source link

Java interop chapter examples are incorrect? #111

Closed ZiyaoWei closed 5 months ago

ZiyaoWei commented 7 months ago

E.g., the example from https://doc.flix.dev/creating-objects.html

import new java.io.File(String): ##java.io.File \ IO as newFile;
newFile("HelloWorld.txt")

does not build with 0.41 as is:

-- Parse Error -------------------------------------------------- /Users/wzy/Projects/chess/traps.flix

>> Parse Error: Invalid input 'j', expected ';', Use, Import or Decls (line 3, column 12):
import new java.io.File(String): ##java.io.File \ IO as newFile;
           ^

Syntactic Context: OtherDecl.

Wrapping it in def main(): Unit \ IO = ... works, but it is not super obvious.

magnus-madsen commented 7 months ago

Indeed. We need to explain that imports should be at the expression level.

ZiyaoWei commented 7 months ago

Might also worth it to add more examples to this chapter - I am trying to write some scripts in Flix and it took me a while to figure out, e.g., how to import a static method, and how to import a static inner class.

magnus-madsen commented 7 months ago

Please do! Contributions welcome!