[MLton] filedes = int (was: Stack size?)

Matthew Fluet fluet@cs.cornell.edu
Mon, 11 Jul 2005 16:36:42 -0400 (EDT)


> The fact that sock and file_desc are implemented by datatypes partially
> arose from the fact that for quite some time, MLton had a very incomplete
> front-end type checker.  Datatypes, requiring a wrap/unwrap at their uses
> (and, hence, handled by even the most primitive type-checker) provided
> better abstraction than signatures.
> 
> Now that there is a complete front-end, we could acheive the same by
> 
> -	datatype file_desc = FD of int
> +	structure FD :> sig type t end = struct type file_desc = int end
> +	type file_desc = FD.t
> 
> Now the type checker will prevent any accidental use of file_desc as an 
> int, with the one exception being that the file_desc may escape through an 
> FFI call (where it will be treated as an int).

Though I think there is still some advantage (though I'm hard pressed to 
put my finger on exactly what the advantage is) to requiring explicit 
pack and unpack functions to witness the coercion.