Ticket #262 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

Introducing a bottom type

Reported by: pascallouis Assigned to: anonymous
Type: defect Priority: major
Component: Spec Version: 4
Keywords: Cc: cormac, waldemar, dherman, graydon

Description

Have we considered adding a bottom type to the type hierarchy? The following code

function (o) {
  switch (typeof o) {
    case 'object': only object processing
    case 'string': only string processing
    ...
  }
}

could be annotated

function (o : nothing) {
  ...
}

The name nothing comes from Scala (it used to be called All but this was found confusing).

Adding a bottom type would allow the meet of two types to be a total function. This is usefull to type check

function (a : (Date,String), b : (Date,Number)) : Date {
  if (a == b) {
    return a;
  } else {
    ...
  }
}

which is correct since the guard a == b is true only if a's type is Date and b's type is Date (the meet of a's type and b's type).

Attachments

Change History

Changed 3 years ago by pascallouis

  • cc changed from cormac to cormac, waldemar

Changed 3 years ago by lth

  • cc changed from cormac, waldemar to cormac, waldemar, dherman

Cormac, Dave -- can we have some comments on this no later than the next f2f (sooner is better).

Pascal, the proposal period is really over. Do we need this change to be type sound? What are the practical benefits?

Changed 3 years ago by lth

  • cc changed from cormac, waldemar, dherman to cormac, waldemar, dherman, graydon

Changed 3 years ago by lth

  • owner deleted
  • component changed from Proposals to Spec

We have a bottom type: the empty union. Pascal and Cormac will chat about how / if this fits into the type system.

Changed 3 years ago by lth

Cormac, Pascal --

we need some movement on this one. What are your thoughts?

Changed 3 years ago by pascallouis

  • status changed from new to closed
  • resolution set to fixed

Based on the rules http://wiki.ecmascript.org/doku.php?id=clarification:type_system#union_types the empty union type () is a natural bottom type.

Note: See TracTickets for help on using tickets.