case expressions/transfers

Stephen Weeks MLton@sourcelight.com
Wed, 9 Jan 2002 19:55:57 -0800


> The extension to the SSA type checker works, and all programs (including a
> self-compile) type-check except polymorphic-recursion.sml.  It fails at
> the initial SSA type-check with 
> mlton: exhaustive case has default
> 
> At first I thought I could modify the monomorphiser, but I think I've
> convinced myself that we won't know which datatype variants are going to
> be necessary until after monomorphising the program; that is, when
> translating a case, I can't know whether or not it is exhaustive.
> 
> So, I think it'll have to go into the XML shrinker.

The problem arises because the monomorphiser removes unused
constructors in datatypes, which it must in order to correctly handle
non-uniform datatypes.  A simpler example that shows the problem is

----------------------------------------
datatype t = A | B

fun f x =
   case x of
      0 => A
    | 1 => A
    | _ => f 3

val _ =
   case f 0 of
      A => 0
    | _ => 1
----------------------------------------

I agree, you can't tell which constructors are going to exist until
you've monomorphised the whole program, so the right fix is to modify
the XML shrinker (or maybe just the closure converter).  I'm happy to
do it if you haven't already.