caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Bug in Hashtbl ?
@ 2002-03-21 15:35 Vesa Karvonen
  2002-03-21 15:46 ` Alain Frisch
  0 siblings, 1 reply; 4+ messages in thread
From: Vesa Karvonen @ 2002-03-21 15:35 UTC (permalink / raw)
  To: caml-list

Hi,

The following program raises an Out_of_memory exception. Is this:
- correct behavior,
- bug in Ocaml 3.04, or
- bug somewhere else?

<--- weird_out_of_memory.ml --->
type vertex =
  | D of vertex list

let _ =
  let rec n0 = D [n1]
  and n1 = D [n0] in
  let vertices = [n0;n1] in
  let res = Hashtbl.create 0 in
    List.iter
      (fun v -> 
  assert (not (Hashtbl.mem res v)) ;
  Hashtbl.add res v (ref 0))
      vertices ;
    ()
<--- weird_out_of_memory.ml --->

Under Cygwin (1.3.10):

  $ ocamlc.opt -o a.exe -g weird_out_of_memory.ml
  $ a.exe
  Fatal error: exception Out_of_memory
  Raised from a C function
  Called from module Weird_out_of_memory, character 220
  Called from module List, character 1856
  Called from module Weird_out_of_memory, character 270

Regards,
  Vesa Karvonen


-------------------
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] 4+ messages in thread

* Re: [Caml-list] Bug in Hashtbl ?
  2002-03-21 15:35 [Caml-list] Bug in Hashtbl ? Vesa Karvonen
@ 2002-03-21 15:46 ` Alain Frisch
  2002-03-21 16:07   ` Vesa Karvonen
  0 siblings, 1 reply; 4+ messages in thread
From: Alain Frisch @ 2002-03-21 15:46 UTC (permalink / raw)
  To: Vesa Karvonen; +Cc: caml-list

On Thu, 21 Mar 2002, Vesa Karvonen wrote:
>
> The following program raises an Out_of_memory exception. Is this:
> - correct behavior,
> - bug in Ocaml 3.04, or
> - bug somewhere else?

I would say "correct behavior"; the manual says, about generic
comparisons:

     Comparison between cyclic structures may not terminate.


Note that it would be costly to implement exact (structural) comparison of
cyclic structures (with a coinductive definition). What you want is
probably to test for physical equality; you can use the functorial version
of hash tables to do that.

-- Alain

-------------------
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] 4+ messages in thread

* Re: [Caml-list] Bug in Hashtbl ?
  2002-03-21 15:46 ` Alain Frisch
@ 2002-03-21 16:07   ` Vesa Karvonen
  0 siblings, 0 replies; 4+ messages in thread
From: Vesa Karvonen @ 2002-03-21 16:07 UTC (permalink / raw)
  To: caml-list

Thanks to everyone for the quick replies.

From: "Alain Frisch" <frisch@clipper.ens.fr>
> On Thu, 21 Mar 2002, Vesa Karvonen wrote:
> >
> > The following program raises an Out_of_memory exception. Is this:
> > - correct behavior,
> > - bug in Ocaml 3.04, or
> > - bug somewhere else?
>
> I would say "correct behavior"; the manual says, about generic
> comparisons:
>
>      Comparison between cyclic structures may not terminate.

Yep, this seems to be the problem.

It might be wise to specifically mention in the Hashtbl documentation that the
functorial version is needed for cyclic structures. The Hashtbl.hash function
documentation easily gices the wrong impression.

> Note that it would be costly to implement exact (structural) comparison of
> cyclic structures (with a coinductive definition). What you want is
> probably to test for physical equality; you can use the functorial version
> of hash tables to do that.

The code is actually a stripped down version of a unit test, so it is not a
problem to change to an acyclic representation. The application isn't using
cyclic structures.

Regards,
  Vesa Karvonen


-------------------
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] 4+ messages in thread

* [Caml-list] Bug in Hashtbl ?
@ 2002-03-21 15:27 Vesa Karvonen
  0 siblings, 0 replies; 4+ messages in thread
From: Vesa Karvonen @ 2002-03-21 15:27 UTC (permalink / raw)
  To: caml-list

Hi,

The following program raises an Out_of_memory exception. Is this:
- correct behavior,
- bug in Ocaml 3.04,
- bug somewhere else?

<--- weird_out_of_memory.ml --->
type vertex =
  | D of vertex list

let _ =
  let rec n0 = D [n1]
  and n1 = D [n0] in
  let vertices = [n0;n1] in
  let res = Hashtbl.create 0 in
    List.iter
      (fun v -> 
  assert (not (Hashtbl.mem res v)) ;
  Hashtbl.add res v (ref 0))
      vertices ;
    ()
<--- weird_out_of_memory.ml --->

Under Cygwin (1.3.10):

  $ ocamlc.opt -o a.exe -g weird_out_of_memory.ml
  $ a.exe
  Fatal error: exception Out_of_memory
  Raised from a C function
  Called from module Weird_out_of_memory, character 220
  Called from module List, character 1856
  Called from module Weird_out_of_memory, character 270

Regards,
  Vesa Karvonen
-------------------
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] 4+ messages in thread

end of thread, other threads:[~2002-03-21 16:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-21 15:35 [Caml-list] Bug in Hashtbl ? Vesa Karvonen
2002-03-21 15:46 ` Alain Frisch
2002-03-21 16:07   ` Vesa Karvonen
  -- strict thread matches above, loose matches on Subject: below --
2002-03-21 15:27 Vesa Karvonen

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