5
votes

I really liked learning ML at college. I find functional programming often a refreshingly elegant way to write certain algorithms. I have heard of F# and played around with that a bit. Still, I've written some interesting functions in ML and would like to integrate them as libraries I could use in other applications.

Usually I paste my functions into the SMLnj interpreter. Is there a way I can compile them down?

5
SMLnj can compile code too... look for CM, the compilation manager. (Though this really doesn't help with integration into other applications.)ephemient

5 Answers

5
votes

You will have to use something like the MLj Compiler. It compiles to Java Byte code. Or you can use the SML.NET compiler to compile to .NET IL.

4
votes

It is common amongst ML for both sides to export to C and then call each others C functions. Just about everything has a FFI library for 'easily' exporting to C.

http://www.smlnj.org/doc/SMLNJ-C/index.html

so to the outside world your sml library would behave like a C library except with out the assiciated segfaults and memory leaks*

*not a guarantee

2
votes

Projects popularize languages. Do the ground work for an interesting and undeniably 'cool' project using ML, and people will flock to the language. For instance,look at Erlang with ejabberd and mochiweb - both cool projects that have done wonders for a one-time-diamond-in-the-rough language like erlang (which is, btw, my development language of choice lately). I for one, would love to see somebody make something rad with ML, the language is a joy to think with.

2
votes

There are several Standard ML compilers. The MLton wiki also contains a benchmark.

I used Moscow ML which compiles Standard ML into bytecode. It's not fast, but it works. MLton is often cited to be the best Standard ML compiler with regard to efficiency.

0
votes

Note that Poly/ML version 5 or later supports both the traditional "heap dump" model, and C-style standalone executables. The documentation on the Poly/ML website is spread over many different spots, some of them with really old dates in the title -- but the system is alive and kicking.

The object-code generation is explained in passing in release notes for the version 5.0 release (we are presently at 5.5): see PolyML.export there.

There is also some Poly/ML C interface, which has been renovated as used for some GUI projects recently. You should ask at the polyml mailing list.