caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] inference engine
@ 2003-09-13  6:58 skaller
  2003-09-13 10:01 ` David Baelde
  0 siblings, 1 reply; 8+ messages in thread
From: skaller @ 2003-09-13  6:58 UTC (permalink / raw)
  To: caml-list

In an example like:

let f (x:int) = 1 + x

the inference engine first examines:

let (f:'a -> 'b) (x:'c) = 1 + x

to specialise 'a, 'b, 'c, and then compares
the infered value of 'c with the constraint on
x, which is 'int' in this case.

For example in

let f (x:int) = x

x is first an un specialised type variable, but the
interface seen by outside clients is constrained to 

	int -> int

Having seen the typing used in polymorphic variants,
of the kind

	[> .. ] and [< .. ]

(I can never remember which is which .. )

I wonder if it isn't possible for the inference
engine to make the type of 'x' on entry to 
the function something like

	[> int ]

meaning 'at least constrainable to '"int" '.
If that were possible the following error would
be caught earlier:

	let f (x:int) = x +. 1.0

at the point 'float' is infered for x, since

	float & [> int] 

is empty. On the other hand, in the case

	let f (x:int) = x

the return type (before constraint is applied) is still

	[> int] & 'a

which is 'a. That is: by attaching 'at least T' for annotation
t (in positive position?? and at most in negative??) to the
type accumulated in the inference engine's tables, we get
earlier error diagnosis, without changing the actual result.

This is 'mandatory typing', but the type which is mandatory isn't
the one of the annotation, but 'some type wider than it'
(or, perhaps narrower in negative position ..??)

Well, I'm not a type theorist, its just an idea ..


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2003-09-21 21:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-13  6:58 [Caml-list] inference engine skaller
2003-09-13 10:01 ` David Baelde
2003-09-14  4:12   ` skaller
2003-09-14  9:29     ` Remi Vanicat
2003-09-14  9:48     ` Alain.Frisch
2003-09-16 19:46       ` skaller
2003-09-21 16:45         ` skaller
2003-09-21 20:43           ` Remi Vanicat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).