Feedback : gives an object its type 

Forum: U Chicago, Com Sci 221, autumn 2000
Re: News Assignment #8, due Thursday 30 November, end of day (Mike O'Donnell)
Re: Question : operator (Michael C. Brizic)
Date: 2000, Nov 26
From: Mike O'Donnell <odonnell@cs.uchicago.edu>

Yes, the colon (:) provides a type to an object, in the form object:type. You only need to use it when ML fails to infer a type, due to overloading of an operator. You don't need it very much in the assignment, and it occurs only occasionally in good ML programming.

For example, in

fun ltchar (a:char) b = a < b;
you probably can't avoid declaring a:char. Notice that ML infers from this that b is also a char, so you don't need to type both of the arguments. The reason that you need to declare a type for one of them is that < is an overloaded symbol, working on integers, characters, and some other types as well.

Similarly, in

fun lexcomplst ([]: char list) chlist2 = true
it's really the use of < later on in the definition that requires disambiguation, but I like to put my type information as early as possible in a definition (I'm not sure why). You could make a good argument for always putting type information as close as possible to the place where it's needed.



Mike O'D.


to: ": gives an object its type"