Tags

Scala on .NET

October 9th, 2007

Scala is now again capable to compile to IL-code so that you can use it from a .NET program!This feature vanished a while ago as the compiler got overhauled and now it is back - according to Martin Odersky, the main figure behind Scala “There are some known problems with exceptions, which we might be able to solve soon.” - but still, the best thing since sliced bread.Here is how to do it (get your paths properly set!):

  1. Get Scala (JVM >1.4.2 needs to be installed)
  2. Install the MSIL package with “sbaz install scala-msil”
  3. Compile your  scala files with “scalac-net  <files>”
  4. Build  a dll from them with  “ilasm /DLL  yourfiles.msil”  (use /EXE if you have a main method to get an executable)
  5. Reference the dll from you .NET project

You can also use .NET libraries from Scala code, for the compilation you have to add the referenced DLLs with the parameter -Xassem-path First.dll;Second.Dll to the scalac-net commandNot so difficult and with some scripts pretty quick to integrate. Of course it will not work to use scala classes that  reference java libraries! Neither will you be able to run (not even compile) scala classes that use external DLLs - unless you want to dive into the JNI hell. A compile switch that warns of “unpure code” to the Scala compiler would be helpful here (Something I should ask for, hopefully I won’t forget).The limitations are not such a problem, the main goal is having a modern language (that is even more powerful than C#, more modern than Java 7 with all discussed extensions) to implement business function that can be directly used on both platforms is a huge win. I am curios what nice libraries will be published for the use on both platforms - distributed as a DLL for .NET or a simple JAR for Java environments.

6 Responses to “Scala on .NET”

  1. Erick Says:

    I’m very excited about this. I’ve been playing with scala and java for about a week and think that scala could be my language of choice. Having dot net support is just icing on the cake.

    Do you know if it works with the mono libraries? I’m primarily a Linux developer.

  2. excellent Says:

    Glad to hear, I’ll spread the word.

  3. Carsten Says:

    Mono should work as well: http://www.nabble.com/Re%3A-.Net–p12793073.html

  4. rektide Says:

    EGADS! I’d given up hope, what a delight! Thanks Martin!!

  5. Rajeev Maskey Says:

    Anybody have idea how to setup proxy for the “sbaz install scala-msil” installation process if one is behind a firewall.

  6. MarkdeVilliers Says:

    to setup a proxy for sbaz -

    Change sbaz.bat

    if “%_JAVA_OPTS%”==”" set _JAVA_OPTS=-Xmx256M -Xms16M

    to

    if “%_JAVA_OPTS%”==”" set _JAVA_OPTS=-Xmx256M -Xms16M -Dhttp.proxyHost={PROXY HOST} -Dhttp.proxyPort={PROXY PORT} -Dhttp.proxyUser={USER NAME} -Dhttp.proxyPassword={PASSWORD}

    Changing the valuse as required.

    Hope that helps.

Leave a Reply