New Polymorphic option type..

Stephen Weeks MLton@research.nj.nec.com
Fri, 4 Feb 2000 15:30:58 -0800 (PST)


> I need to add a new polymorphic option type constructor, can some give a quick
> list of what files I have to hack to do this.
> 
> i.e. datatype 'a option = NONE | SOME of 'a

This is not too difficult as long as the type is introduced as a
normal datatype early on in the compilation process (basically, before
type inference), which is what is done for lists.  In this case, you
may be able to get away with modifying the following.

ast/prim-cons
ast/prim-tycons
elaborate/elaborate-env  (fun prim() ...)

You then may have to go through a bit of work to make sure that the
datatype is kept around (e.g. by passes that remove unused datatypes
and constructors) until the pass you need it.  I don't know the files
offhand, but I would guess 

xml/monomorphise
xml/simplify-types
cps/simplify-types
cps/remove-unused-constructors

OTOH, if you want a type that is propagated in a special way through
the entire compiler (like ref, array, or vector), then this is not
such an easy thing to do and I would recommend against it.  If you'll
explain why you'd like to I'll be happy to try and help find away
around this.  The problem is, if the type isn't just a normal
datatype, then you'll have to modify all of the analyses (e.g. flow
analysis, constant propagation, useless analysis, ...) to handle it
properly.  That would be a pretty big task.

> can I also assume the "0" is never valid for enums?

I don't understand this question.