Could we have syntax support for defining opaque types?

Right now the only way to define an opaque type is to do so via an interface. eg.

module Length: {
  type t
  let feet: int => t
  let meters: int => t
} = {
  type t = Feet(int) | Meters(int)

  let feet = n => Feet(n)
  let meters = n => Meters(n)
}

What if we could take the lead of Flow’s opaque types and have the ability to mark the type as opaque to anyone outside of the module eg.

module Length = {
  opaque type t = Feet(int) | Meters(int)

  let feet = n => Feet(n)
  let meters = n => Meters(n)
}

Length.t would be opaque everywhere apart from inside of the Length module itself.

8 Likes