tags:

views:

215

answers:

2

I see that the SML/NJ includes a queue structure. I can't figure out how to use it. How do I use the additional libraries provided by SML/NJ?

A: 

I don't have a complete answer for you but I could point you in the right direction. You should look up using the compilation manager (CM) which is built in to SML/NJ. You can think of it as Make for SML.

To use a library from the SML/NJ library you then add smlnj-lib.cm to the CM description file of your application. Then you can use the declarations such as Queue from that library.

The smlnj website has some documentation about the compilation manager.

Hope this at least points you in the right direction.

Vincent Ramdhanie
+1  A: 

The Queue structure is not specified by SML '97, but it is present in SML/NJ's top-level environment.

$ sml
Standard ML of New Jersey v110.69 [built: Fri Mar 13 16:02:47 2009]
- Queue.mkQueue ();
[autoloading]
[library $SMLNJ-LIB/Util/smlnj-lib.cm is stable]
[autoloading done]
stdIn:1.1-1.17 Warning: type vars not generalized because of
   value restriction are instantiated to dummy types (X1,X2,...)
val it = - : ?.X1 Queue.queue
- 

You can open a structure. This lets you avoid typing Queue. in front of everything. It's discouraged to do this at the top-level, though, because it pollutes the environment and makes it much less obvious what you're depending on. (Within another structure I'd say it might be acceptable in some situations.)

$ sml
Standard ML of New Jersey v110.69 [built: Fri Mar 13 16:02:47 2009]
- open Queue;
[autoloading]
[library $SMLNJ-LIB/Util/smlnj-lib.cm is stable]
[autoloading done]
opening Queue
  type 'a queue
  exception Dequeue
  val mkQueue : unit -> 'a queue
  val clear : 'a queue -> unit
  val isEmpty : 'a queue -> bool
  val enqueue : 'a queue * 'a -> unit
  val dequeue : 'a queue -> 'a
  val next : 'a queue -> 'a option
  val delete : 'a queue * ('a -> bool) -> unit
  val head : 'a queue -> 'a
  val peek : 'a queue -> 'a option
  val length : 'a queue -> int
  val contents : 'a queue -> 'a list
  val app : ('a -> unit) -> 'a queue -> unit
  val map : ('a -> 'b) -> 'a queue -> 'b queue
  val foldl : ('a * 'b -> 'b) -> 'b -> 'a queue -> 'b
  val foldr : ('a * 'b -> 'b) -> 'b -> 'a queue -> 'b
- mkQueue ();
stdIn:3.1-3.11 Warning: type vars not generalized because of
   value restriction are instantiated to dummy types (X1,X2,...)
val it = - : ?.X1 queue
- 
ephemient