[MLton-user] Vesa's generics library

Vesa Karvonen vesa.a.j.k at gmail.com
Sat Jan 5 03:14:38 PST 2008


On Jan 5, 2008 11:54 AM, Michele Simionato <michele.simionato at gmail.com> wrote:
> I am trying to write some code that would benefit from Vesa Karvonen's
> generics library. [...] The issue is that I would like to play with the library from
> the REPL and mlton has no REPL, so I would like to how to use the library
> from SML/NJ. I don't find the build instructions so I need some help. [...]

The easiest way to try a part of the lib from SML/NJ's REPL is to use
the CM file for the default combination (Eq, Ord, Hash, Pretty) of
generics that comes with the library.  To do that, follow the
following SML/NJ interaction in the generic/unstable directory:

Standard ML of New Jersey v110.66 [built: Thu Nov 15 12:22:47 2007]
- CM.make "lib-with-default.cm" ;
[...lots of output...]
- open Generic ;
[...lots of output...]
- val t = list int ;
val t = - : int list Rep.t
- show t [3, 1, 4, 1] ;
val it = "[3, 1, 4, 1]" : string
- hash t [3, 1, 4, 1] ;
val it = 0wx2E4DC475 : word
- eq t ([3], [1, 4, 1]) ;
val it = false : bool
- ord t ([3], [1, 4, 1]) ;
val it = GREATER : order

Unlike MLton's MLB system, SML/NJ's CM isn't flexible enough to be
able to create a combination of generics conveniently.  If you look
into lib-with-default.cm, you can see that it includes the file
detail/generic.sml, which is a generated file (a concatenation of
"with" files) for the combination.  If you want to use an ad hoc
combination of generics, you can do the same, i.e. create a
concatenation of "with" files for the desired combination for use with
SML/NJ's CM.  Alternatively, you can use the necessary files from
SML/NJ's REPL.  For example, the following shows how one could use the
pickling generic (evaluate the below in SML/NJ's REPL in the
generic/unstable dir):

CM.make "lib.cm" ;
app use
    ["with/generic.sml",
     "with/eq.sml",
     "with/type-info.sml",
     "with/type-hash.sml",
     "with/data-rec-info.sml",
     "with/hash.sml",
     "with/some.sml",
     "with/pickle.sml",
     "with/close.sml",
     "with/extra.sml"] ;

open Generic ;
val t = list int ;
val x = [3, 1, 4, 1] ;
val p = pickle t x ;
val x' = unpickle t p ;

-Vesa Karvonen



More information about the MLton-user mailing list