Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] type proofs
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Francois Pottier <francois.pottier@i...>
Subject: Re: [Caml-list] type proofs

On Fri, Dec 07, 2001 at 01:28:18PM -0800, Charles Martin wrote:
> I have the usual kind of type error:
> 
> Values do not match:
>   val send : ('a, int, 'b) t -> 'a -> int
> is not included in
>   val send : ('a, 'b, 'c) t -> 'a -> int

Your implementation is well-typed, but less general than what's
declared in your interface. The right thing to do is to add type
annotations to your code to help pinpoint the error location.
One would like to write:

  let send (x : ('a, 'b, 'c) t) (y : 'a) = ...

Unfortunately, this will not help, because O'Caml interprets these
type variables as existentially bound, i.e. it thinks it is OK to
instantiate 'b with int. There is no way, as far as I know, to require
them to be intepreted as universally bound. One work-around here is
to write:

  let send (x : ('a, bool, 'c) t) (y : 'a) = ...

Here, if your code were general enough, your implementation would still
typecheck. However, because the inferred type mentions int and you have
required bool, a type error will arise somewhere, and that should help
you locate the error. (Here, I have used bool, but any concrete or
abstract type other than int would do.) Of course, you'll need to remove
the annotation when done.

I hope this helps,

-- 
François Pottier
Francois.Pottier@inria.fr
http://pauillac.inria.fr/~fpottier/
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr