caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* What does underscore mean in this type expression?
@ 2008-08-30 11:27 Richard Jones
  2008-08-30 11:38 ` [Caml-list] " Christophe TROESTLER
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Jones @ 2008-08-30 11:27 UTC (permalink / raw)
  To: caml-list

I'm seeing this type error.  Notice the difference is a lowly
underscore character.

  The implementation libvirt.ml does not match the interface libvirt.cmi:
  Values do not match:
    val get_domains :
      (_[> `R ] as 'a) Connect.t ->
      ?want_info:bool ->
      Domain.list_flag list -> 'a Domain.t list * Domain.info list
  is not included in
    val get_domains :
      ([> `R ] as 'a) Connect.t ->
      ?want_info:bool ->
      Domain.list_flag list -> 'a Domain.t list * Domain.info list

This syntax doesn't appear to be documented in the manual (unless it's
related to '_a).  What does it mean?

I can supply some reproducer code if needed, but the code is rather
long at the moment.

Rich.

-- 
Richard Jones
Red Hat


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

* Re: [Caml-list] What does underscore mean in this type expression?
  2008-08-30 11:27 What does underscore mean in this type expression? Richard Jones
@ 2008-08-30 11:38 ` Christophe TROESTLER
  2008-08-30 13:03   ` Richard Jones
  0 siblings, 1 reply; 5+ messages in thread
From: Christophe TROESTLER @ 2008-08-30 11:38 UTC (permalink / raw)
  To: Richard Jones; +Cc: OCaml Mailing List

On Sat, 30 Aug 2008 12:27:18 +0100, Richard Jones wrote:
> 
>     val get_domains :
>       (_[> `R ] as 'a) Connect.t ->
>   is not included in
>     val get_domains :
>       ([> `R ] as 'a) Connect.t ->
> 
> This syntax doesn't appear to be documented in the manual (unless it's
> related to '_a).  What does it mean?

It is a weak type as you guessed.  To convince you of that, here is
some code:

# let x = ref `X;;
val x : _[> `X ] ref = {contents = `X}

Cheers,
C.


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

* Re: [Caml-list] What does underscore mean in this type expression?
  2008-08-30 11:38 ` [Caml-list] " Christophe TROESTLER
@ 2008-08-30 13:03   ` Richard Jones
  2008-08-30 13:57     ` Christophe TROESTLER
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Jones @ 2008-08-30 13:03 UTC (permalink / raw)
  To: caml-list

On Sat, Aug 30, 2008 at 01:38:31PM +0200, Christophe TROESTLER wrote:
> On Sat, 30 Aug 2008 12:27:18 +0100, Richard Jones wrote:
> > 
> >     val get_domains :
> >       (_[> `R ] as 'a) Connect.t ->
> >   is not included in
> >     val get_domains :
> >       ([> `R ] as 'a) Connect.t ->
> > 
> > This syntax doesn't appear to be documented in the manual (unless it's
> > related to '_a).  What does it mean?
> 
> It is a weak type as you guessed.  To convince you of that, here is
> some code:
> 
> # let x = ref `X;;
> val x : _[> `X ] ref = {contents = `X}

OK ... so how to get rid of the error?  Even supplying a full type for
get_domains in the implementation doesn't get rid of it.

Here's the code if anyone wishes to try:

  http://www.annexia.org/tmp/libvirt.mli
  http://www.annexia.org/tmp/libvirt.ml

  $ ocamlc -c libvirt.mli
  $ ocamlc -c libvirt.ml
  The implementation libvirt.ml does not match the interface libvirt.cmi:
  Values do not match:
  [etc]

Rich.

-- 
Richard Jones
Red Hat


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

* Re: [Caml-list] What does underscore mean in this type expression?
  2008-08-30 13:03   ` Richard Jones
@ 2008-08-30 13:57     ` Christophe TROESTLER
  2008-08-30 19:29       ` Richard Jones
  0 siblings, 1 reply; 5+ messages in thread
From: Christophe TROESTLER @ 2008-08-30 13:57 UTC (permalink / raw)
  To: rich; +Cc: caml-list

On Sat, 30 Aug 2008 14:03:10 +0100, Richard Jones wrote:
> 
> > # let x = ref `X;;
> > val x : _[> `X ] ref = {contents = `X}
> 
> OK ... so how to get rid of the error?  Even supplying a full type for
> get_domains in the implementation doesn't get rid of it.
> 
> Here's the code if anyone wishes to try:
> 
>   http://www.annexia.org/tmp/libvirt.mli
>   http://www.annexia.org/tmp/libvirt.ml
> 
>   $ ocamlc -c libvirt.mli
>   $ ocamlc -c libvirt.ml

Here is the crux of your problem

let f = let a = ref 0 in fun (x : [> `R ]) ->  x;;

If you hoist [let have_list_all_domains = ref None] outside [let
get_domains], then it works fine.  The type checker could certainly be
slightly improved [1] there but I do not know how difficult it is.

C.

---
[1] And maybe also the compiler: a rough check seem to indicate that
hiding the variable in the definition of f is slightly slower. 


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

* Re: [Caml-list] What does underscore mean in this type expression?
  2008-08-30 13:57     ` Christophe TROESTLER
@ 2008-08-30 19:29       ` Richard Jones
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Jones @ 2008-08-30 19:29 UTC (permalink / raw)
  To: Christophe TROESTLER; +Cc: caml-list

On Sat, Aug 30, 2008 at 03:57:54PM +0200, Christophe TROESTLER wrote:
> On Sat, 30 Aug 2008 14:03:10 +0100, Richard Jones wrote:
> > 
> > > # let x = ref `X;;
> > > val x : _[> `X ] ref = {contents = `X}
> > 
> > OK ... so how to get rid of the error?  Even supplying a full type for
> > get_domains in the implementation doesn't get rid of it.
> > 
> > Here's the code if anyone wishes to try:
> > 
> >   http://www.annexia.org/tmp/libvirt.mli
> >   http://www.annexia.org/tmp/libvirt.ml
> > 
> >   $ ocamlc -c libvirt.mli
> >   $ ocamlc -c libvirt.ml
> 
> Here is the crux of your problem
> 
> let f = let a = ref 0 in fun (x : [> `R ]) ->  x;;
> 
> If you hoist [let have_list_all_domains = ref None] outside [let
> get_domains], then it works fine.  The type checker could certainly be
> slightly improved [1] there but I do not know how difficult it is.

Yes, that fixed it, thanks.

> [1] And maybe also the compiler: a rough check seem to indicate that
> hiding the variable in the definition of f is slightly slower. 

It use this idiom quite a lot to emulate private (static) variables.

Rich.

-- 
Richard Jones
Red Hat


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

end of thread, other threads:[~2008-08-30 19:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-30 11:27 What does underscore mean in this type expression? Richard Jones
2008-08-30 11:38 ` [Caml-list] " Christophe TROESTLER
2008-08-30 13:03   ` Richard Jones
2008-08-30 13:57     ` Christophe TROESTLER
2008-08-30 19:29       ` Richard Jones

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).