[MLton-user] The Generic Programming Library is great

Ville Laurikari ville at laurikari.net
Thu Jan 31 13:11:17 PST 2008


Hi all,

I've recently taken the Generic Programming Library by Vesa Karvonen
into use and though it would be a good idea to share the experience.
I urge all SML'ers to take a look at this library.  Chances are you
can do away with a lot of your one-off ad-hoc code and offload the
tasks to this library.

The library is available in the mltonlib:
  http://mlton.org/cgi-bin/viewsvn.cgi/mltonlib/trunk/com/ssh/generic/unstable

This library is seriously good stuff.  For example, it allows one to
do things like this:

  open Generic
  println (show (list int) [1, 2, 3, 4])
  println (show (vector real) (Vector.fromList [1.2, 5.6, 0.0]))

In other words, "printf" debugging in SML just got fun and easy.
Using it is almost like the built-in `print' function in Python or
`display' or `write' in Scheme.  The only additional thing you need to
do is describe the type in the first argument to `show', which is no
problem.  Never again do you have to write yet another ad-hoc loop to
print your data.

You can pretty-print stuff, too, if you want:
   http://mlton.org/cgi-bin/viewsvn.cgi/mltonlib/trunk/com/ssh/generic/unstable/public/value/pretty.sig

You can read your printed values back with the generic parser:
   http://mlton.org/cgi-bin/viewsvn.cgi/mltonlib/trunk/com/ssh/generic/unstable/public/value/read.sig

The combination of `show' (or `pretty') and `read' is almost like
`read' and `write' in Scheme (or your favorite lisp).  I've
implemented the configuration file for one of my small programs with
this, and got rid of a bunch of ad-hoc dumping and parsing code I used
previously.

There's pickling:
   http://mlton.org/cgi-bin/viewsvn.cgi/*checkout*/mltonlib/trunk/com/ssh/generic/unstable/public/value/pickle.sig

Pickling means converting values to a platform independent and
relatively space efficient binary format (and back, of course).  You
can then dump that data to files, send it over the network, and so
on.

Even show/read and pickle/unpickle alone are wonderful but there's
more, such as generic equality testing, hashing, and sorting.  Check
out the README for more details.


--
Ville



More information about the MLton-user mailing list