Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* weird behavior with built-in ignore function (a bug?)
@ 2007-11-23 16:09 Peng Zang
  2007-11-23 16:19 ` [Caml-list] " Vincent Aravantinos
  2007-11-24  0:31 ` Julien Moutinho
  0 siblings, 2 replies; 6+ messages in thread
From: Peng Zang @ 2007-11-23 16:09 UTC (permalink / raw)
  To: caml-list

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi all,

I have run into what appears to be very odd behavior with the built-in
function "ignore".  I will demonstrate below.  It's a little
complicated, but it's the smallest testcase I could make it:

# type 'a fruit = 'a
and 'b veggie = 'b
and ('a,'b) kitchen = { source : <make : 'a fruit>;
                        sink : <trans : 'a fruit -> 'b veggie>; }
;;

# let bar sink x = sink#trans x;;
val bar : < trans : 'a -> 'b; .. > -> 'a -> 'b = <fun>

# let foo src snk =
    let m = { source = src; sink = snk } in
      ignore (bar m.sink m.source#make);
      ignore (bar m.sink m.source#make);
      ()
;;
val foo : < make : 'a fruit > -> < trans : 'a fruit -> '_b veggie > -> unit = 
<fun>


Basically, we have two objects.  One is producing fruits (source) and
the other is transforming them into vegetables (sink).  Note the
inferred typesig of foo, it thinks the trans method returntype is '_b
veggie.  This seems strange.  I think it should return a fully
polymorphic 'b veggie.

To verify.  I now re-define foo without the use of ignore:

# let foo src snk =
    let m = { source = src; sink = snk } in
    let _ = bar m.sink m.source#make in
    let _ = bar m.sink m.source#make in
      ();;
val foo : < make : 'a fruit > -> < trans : 'a fruit -> 'b veggie > -> unit = 
<fun>

This time the return type for trans is fully polymorphic!  Using
ignore as in the first case broke something.

For a strange turn, I make my own ignore function and redefine foo
with that:

# let myignore x = ();;
val myignore : 'a -> unit = <fun>
# let foo src snk =
  let m = { source = src; sink = snk } in
    myignore (bar m.sink m.source#make);
    myignore (bar m.sink m.source#make);
    ()
;;
val foo : < make : 'a fruit > -> < trans : 'a fruit -> 'b veggie > -> unit = 
<fun>

This also yields returns a fully polymorphic veggie!  So it's
something unique to the build-in ignore function?

So now my puzzling question: what is going on?  What is wrong with the
build-in ignore function that would make it mess up the return type of
the trans method?  Is this a bug?

Thanks,

Peng

PS. I'm using OCaml 3.09.3, haven't tried with 3.10
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)

iD8DBQFHRvtLfIRcEFL/JewRAlaUAKDILTX5yx7vsK0z8qRWFXMosywfUgCfcFqv
zfcI8DJ4qOuDzF+S3zsrFBM=
=fBnk
-----END PGP SIGNATURE-----


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

end of thread, other threads:[~2007-11-25 14:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-23 16:09 weird behavior with built-in ignore function (a bug?) Peng Zang
2007-11-23 16:19 ` [Caml-list] " Vincent Aravantinos
2007-11-24  0:31 ` Julien Moutinho
2007-11-24 18:48   ` Peng Zang
2007-11-25  6:05     ` Julien Moutinho
2007-11-25 14:21       ` Peng Zang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox