[MLton-user] Destructive update
Joe Hurd
joe.hurd@comlab.ox.ac.uk
Wed, 8 Feb 2006 14:17:45 +0000
Hi guys,
firstly, let me say thank you for your hard work on MLton: I use
programs compiled with MLton to perform the back end analysis for a
community website I maintain, and this entails a 10 hour CPU intensive
run nearly every day. That said, I'd like to reduce this time, and the
questions below are designed to help me with this.
1. I compile all my programs with the command
mlton -basis 1997 -verbose 1 -runtime 'ram-slop 0.4'
The 1997 basis is so I can also develop with Moscow ML, mainly for its
read-eval-print loop. The ram-slop is so I can comfortably run 2
programs compiled like this on my machine without thrashing. However,
one of my programs needs a lot of RAM, and so I invoke it with
program @MLton ram-slop 0.8 -- arguments
However, I've noticed that it only ever uses 40% of the machine's RAM,
even though I strongly suspect it would use more if it could. Am I
correctly overriding the ram-slop parameter that I set during
compilation?
2. My ML programming style, if I can call it that, makes intensive use
of dictionaries, which have the following signature
new : ('a * 'a -> order) -> ('a,'b) dict
peek : ('a,'b) dict -> 'a -> 'b option
insert : ('a,'b) dict -> 'a * 'b -> ('a,'b) dict
foldl : ('a * 'b * 'c -> 'c) -> 'c -> ('a,'b) dict -> 'c
I use them like arrays with a polymorphic key, and much of the time
they could safely be destructively updated without breaking my
programs.
So all this preamble is leading to two sub-questions:
a) Should I be using some other container type? How is this problem
usually solved in the source code of the MLton compiler?
b) Have you thought of doing a compiler analysis to see what data
structures can be destructively updated? It's not my field of
expertise, but I believe Clean-style uniqueness types can be used to
do this, and I'm sure there are other methods that I'm ignorant of.
Two nice things about this analysis are that (i) the programmer
doesn't need to know anything about it, and (ii) if the analysis
returns "I don't know" the compiler can just do what it would normally
do.
Regards,
Joe