]>
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> > (b) the codomain is mis-specified, we actually have
> > List.hd: 'a list -> Some 'a
>
> Funny, I always assumed that the domain of List.hd was "'a list - []".
Yes, indeed. Were List.hd of type 'a list -> 'a option, we'd be stuck
if we ever wanted actually to _use_ the value: any function that
attempted to extract it (say f : 'a option -> 'a) would have to have a
similar type (f : 'a option -> 'a option).
The same problem would ensue if we had explicit exception typing:
List.hd : 'a list -> 'a with_possible_exception
extract : 'a with_possible_exception -> 'a option
really_extract : 'a option -> 'a with_possible_exception
and so on...!
The only way out of this mess is to add a monad. OCaml already has
one: return is implicit, bind is called ";", and the monad operations
include "raise" and "try ... with ...".
HTH.
--KW 8-)