0

I'm trying to read the source of Isabelle even though I'm a beginner of Standard ML. I arrive at the structure Unsynchronized in src/Pure/Concurrent/unsynchronized.ML, which seems for the multi-thread programming. It includes

...

structure Unsynchronized: UNSYNCHRONIZED =
struct

datatype ref = datatype ref;

...

end;

ML_Name_Space.forget_val "ref";
ML_Name_Space.forget_type "ref";

and I cannot understand datatype ref = datatype ref;. It's not in the usual form of datatype declaration.

As an experiment, in the REPL of poly/ML, I got

> datatype ref = datatype ref;
datatype 'a ref = ref of 'a

and so this declaration seems doing nothing or giving a type constructor synonym Unsynchronized.ref = ref (also Unsynchronized.ref seems not being distinguished from ref at all).

So my questions are:

  1. What kind of syntax structure does datatype ref = datatype ref; have?
  2. What is the semantics (or meaning?) of datatype ref = datatype ref;?
  3. What is the usage of such a type constructor synonym declaration? (Just for the clarity in semantics?)

Addendum: The functions

ML_Name_Space.forget_val
ML_Name_Space.forget_type

are defined in src/Pure/ML/ml_name_space.ML as

val forget_val = PolyML.Compiler.forgetValue;
val forget_type = PolyML.Compiler.forgetType;

and so after loading (?) unsynchronized.ML, the original type constructor ref is not available anymore. Probably, this answers Q.3 partially.

opus26
  • 38
  • 7

1 Answers1

2
datatype ref = datatype ref

means that we create a synonym for the SML builtin type ref. It has the same constructor (ref) as the original one.

The commit does not provide any motivation why this was introduced, but I would not be surprised to hear that this comes from

(i) supporting the compilers PolyML and Moscow ML.

(ii) putting ref into a proper module for more clarity, making it possible to call other datypes ref (there is one in src/Pure/facts.ML)

Mathias Fleury
  • 2,221
  • 5
  • 12
  • Thank you for the answer. I also find the grammar for `datatype ref = datatype ref` in Appendix G. 6 of "The Definition of Standard ML (Revised)". I didn't know this declaration "Replication of Datatypes". Also, your remark on `src/Pure/facts.ML` motivates the replication very clearly. I cannot understand the point (i), but it's maybe just because my lack of experience and I only care poly/ML in the current source code reading. – opus26 Dec 11 '22 at 08:36
  • Anyway, I should have consulted the "definition" though it is difficult to follow for a beginner like me. – opus26 Dec 11 '22 at 08:40
  • 1
    A long time ago, Isabelle supported several SML compilers. And they slightly differed in their semantics (IIRC moscow ml required some additional ';' at the end of modules definition). Maybe there was some difference in module `ref` is in. – Mathias Fleury Dec 11 '22 at 10:08
  • Ah... I see (probably). I also confused once on the type of `chr` in Poly/ML (int -> char) and in Isabelle/ML (int -> string) and this is an incompatibility of SML '90 and SML '97. (Later I found `chr` is redefined in Isabelle/ML.) In "Definition (revised)", I now found that ';' matter is also in 90 vs 97 incompatibility... Such subtlety is a bit difficult for me... Anyway, thank you very much, Mathias! – opus26 Dec 11 '22 at 12:24