MLton 20100608 GenerativeDatatype
Home  Index  
In Standard ML, datatype declarations are said to be generative, because each time a datatype declaration is evaluated, it yields a new type. Thus, any attempt to mix the types will lead to a type error at compile-time. The following program, which does not type check, demonstrates this.
functor F () =
   struct
      datatype t = T
   end
structure S1 = F ()
structure S2 = F ()
val _: S1.t -> S2.t = fn x => x

Generativity also means that two different datatype declarations define different types, even if they define identical constructors. The following program does not type check due to this.

datatype t = A | B
val a1 = A
datatype t = A | B
val a2 = A
val _ = if true then a1 else a2

Also see


Last edited on 2010-03-02 15:11:35 by MatthewFluet.