[MLton] Minor front-end extension

Stephen Weeks MLton@mlton.org
Wed, 11 Aug 2004 10:41:31 -0700


> One idiom that would probably be hard to nail that I use all the
> time is the case where a structure has a complicated (i.e., long)
> datatype in it. 
...
> The idiom that I use is
>
>         structure S =
>            struct
>               ...
>               datatype t = ....
>               ...
>            end
> 
>         structure S =
>            S: sig
>                  ...
>                  datype t = datatype S.t
>                  ...
>               end

You can use the stylized form of structure binding for your second S.

   structure S: sig
		   datatype t = datatype S.t
		end = S

As to the first S, you could hide it in a local.

local
   structure S =
      struct
	 datatype t = T
      end
in
   structure S: sig
		   datatype t = datatype S.t
		end = S
end

Although, it's not entirely clear what our definition of toplevel is,
so it's not clear whether this would generate a warning or not.  To be
certain, you could avoid using a structure at all for the datatype.

local
   datatype t = T
in
   structure S:
      sig
	 datatype t = datatype t
      end =
      struct
	 datatype t = datatype t
      end
end

Or, you could use let to hide the datatype.

structure S =
   let
      datatype t = T
   in
      struct
	 datatype t = datatype t
      end : sig
	       datatype t = datatype t
	    end
   end

But that doesn't use the stylized form, so I'd probably go with the
local, which is also easier to read.

Sadly, SML/NJ fails on these last two due to some bug.