[MLton] withtype in signature?

Matthew Fluet fluet@cs.cornell.edu
Tue, 6 Sep 2005 07:58:36 -0400 (EDT)


> I want to have something like
>    datatype test = A of foo * baz | B
>    withtype foo = string * test
>    and baz = int
> in a signature, but I see that it is explicitly forbidden by ml.grm.
>
> Why is 'withtype' not allowed in signatures? The standard?

Correct.  The grammar of the Definition does not admit "withtype" in 
signatures.

> How do I achieve the same effect? (a public recursive datatype)
>
> I know that I could simply replace all the occurrences of foo
> and baz in the public definition, like:
>
> datatype test = A of (string * test) * int | B
> type foo = string * test
> and baz = int

That is one recourse.  Another, almost as verbose means is to define a 
structure with exactly the datatype of interest and then bind to that in 
the signature:

structure T = struct
   datatype test = A of foo * baz | B
   withtype foo = string * test
   and baz = int
end

signature S = sig
   datatype test = datatype T.test
   type foo = T.foo
   type baz = T.baz
end

> However, this seems rather silly; in the real source code, the
> abbreviation greatly improves readability and brevity. One would
> think that is most important in the context of signatures...

Agreed, but when every implementation throws in conveniences for what its 
developers encounter, you end up with the fractured landscape of 
SML+<extension> and portability problems.