[MLton] sequenceNonUnit

Vesa Karvonen vesa.karvonen@cs.helsinki.fi
Fri, 29 Jul 2005 03:11:55 +0300


Quoting Henry Cejtin <henry.cejtin@sbcglobal.net>:
[...]
> That is why the sequenceUnit option causes the error.

I know, but the problem is to implement 'sequenceNonUnit warn'. The current
implementation technique of (destructively) unifying the type of the ignored
expression with unit simply does not work, because it may cause a type error
in a context other than the ignored expression.

> After all, the whole point is warning people about non-unit expressions used
> in a context where the value is `ignored'.

Yes, this is the intention I get from the explanation on the Wiki page. However,
the current implementation (of sequenceUnit) feels quite different to me. It
feels less about giving diagnostics ("warning people") and more about changing
the typing of expressions. Consider the following function:

  fun latentError dummy = while false do dummy

With "sequenceUnit false" the type of latentError is

  'a -> unit .

However, with "sequenceUnit true" the type is changed to

  unit -> unit .

In other words, rather than merely giving additional diagnostics, "sequenceUnit
true" actually changes the typing of the program.

Again, changing the typing of the program to implement 'sequenceNonUnit warn'
(to give warnings rather than errors) would not work, because changing the
typing could cause type errors later. For example, in

  fun latentError dummy = while false do dummy
  val () = latentError 1

changing the typing of latentError to `unit -> unit' would cause a type
error (rather than a warning) at `latentError 1'.

-Vesa Karvonen