F#: Can't hide a type abbreviation in a signature? Why not?

Posted by Nels Beckman on Stack Overflow See other posts from Stack Overflow or by Nels Beckman
Published on 2010-05-18T08:52:05Z Indexed on 2010/05/18 11:30 UTC
Read the original article Hit count: 204

Filed under:

In F#, I'd like to have what I see as a fairly standard Abstract Datatype:

// in ADT.fsi
module ADT
  type my_Type

// in ADT.fs
module ADT
  type my_Type = int

In other words, code inside the module knows that my_Type is an int, but code outside does not. However, F# seems to have a restriction where type abbreviations specifically cannot be hidden by a signature. This code gives a compiler error, and the restriction is described here.

If my_Type were instead a discriminated union, then there is no compiler error. My question is, why the restriction? I seem to remember being able to do this in SML and Ocaml, and furthermore, isn't this a pretty standard thing to do when creating an abstract datatype?

Thanks

© Stack Overflow or respective owner

Related posts about F#