From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id D7906BBAF for ; Sun, 9 Aug 2009 15:20:21 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoYCABpqfkpRZ90wkWdsb2JhbACaSwEBAQEJCwoHEwOweYQYBYI2 X-IronPort-AV: E=Sophos;i="4.43,349,1246831200"; d="scan'208";a="34202494" Received: from mtaout02-winn.ispmail.ntl.com ([81.103.221.48]) by mail1-smtp-roc.national.inria.fr with ESMTP; 09 Aug 2009 15:20:21 +0200 Received: from aamtaout02-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout02-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20090809132021.FPHG6611.mtaout02-winn.ispmail.ntl.com@aamtaout02-winn.ispmail.ntl.com>; Sun, 9 Aug 2009 14:20:21 +0100 Received: from romulus.metastack.com ([81.102.132.77]) by aamtaout02-winn.ispmail.ntl.com (InterMail vG.2.02.00.01 201-2161-120-102-20060912) with ESMTP id <20090809132019.KOXW21638.aamtaout02-winn.ispmail.ntl.com@romulus.metastack.com>; Sun, 9 Aug 2009 14:20:19 +0100 Received: from Tenor ([172.16.0.15]) (authenticated bits=0) by romulus.metastack.com (8.14.2/8.14.2) with ESMTP id n79DKFaT006825 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Sun, 9 Aug 2009 14:20:16 +0100 From: "David Allsopp" To: "'ivan chollet'" Cc: , "'Michel Mauny'" References: <000301ca184b$032b8cc0$0982a640$@chollet@free.fr> <000701ca184d$29507e90$7bf17bb0$@metastack.com> <001001ca18c7$37b22220$a7166660$@chollet@free.fr> <001501ca18cc$d59a61a0$80cf24e0$@metastack.com> <001201ca18e9$c4456810$4cd03830$@chollet@free.fr> In-Reply-To: <001201ca18e9$c4456810$4cd03830$@chollet@free.fr> Subject: RE: [Caml-list] Re: ocaml sefault in bytecode: unanswered questions Date: Sun, 9 Aug 2009 14:20:15 +0100 Message-ID: <000301ca18f4$22c31ea0$68495be0$@metastack.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AcoYSwIujdfw2t6+QYu8dTW6a2iSLQAALp+gABHYngAADbFQUAAA4VFAAAkdLSA= Content-Language: en-gb Organization: MetaStack Solutions Ltd. X-Scanned-By: MIMEDefang 2.65 on 81.102.132.77 X-Cloudmark-Analysis: v=1.0 c=1 a=eLVQcBipswAA:10 a=ZOzjf2MOAAAA:8 a=nMbaMaWW9qO64BgEamAA:9 a=xVKSJ7JzF1M8V-EPwbkA:7 a=2m3cDdah-IDj5PuiI789VuB8SG0A:4 X-Spam: no; 0.00; ocaml:01 bytecode:01 bool:01 stdlib:01 pervasives:01 pervasives:01 bug:01 equality:01 equality:01 wrote:01 terminate:01 terminate:01 caml-list:01 cyclic:01 cyclic:01 Ivan Chollet wrote: > See the following snippet: > > # let q =3D Queue.create () in >=A0 Queue.push 0 q; >=A0 q =3D=3D q;; > - : bool =3D true > > Standard behavior. > Now let see this: > > # let q =3D Queue.create () in >=A0=A0Queue.push 0 q; > q =3D q;; > =20 > which hangs for ever... Internally, Queues are a cyclic data structure (see stdlib/queue.ml in = the sources). The documentation for Pervasives.(=3D) notes "Equality between cyclic data structures may not terminate". If you want to compare two = queues for structural equality you'd have to fold the two Queues to a list and = then compare those. Perhaps a Queue isn't the most appropriate data structure = for what you're doing, therefore (functional queues wouldn't suffer from = this problem but note that their performance characteristic is subtly = different from an imperative queue)? Alternatively, if Queue.compare would be a = handy function, you could try raising a feature-request for it in Mantis. > I would have thought physical equality implies structural equality, = but it doesn't seem like it. > Can you please explain to me what=92s wrong there? "It does" - but only with the given caveat that comparison of cyclic structures may not terminate. Pervasives.compare has a similar = restriction, although note that [compare q q] in your example does return 0 (which is lucky or it would be a bug as the docs for Pervasives.(=3D=3D) state = that [x =3D=3D y] =3D> [compare x y =3D 0]). The notes in http://caml.inria.fr/mantis/view.php?id=3D3322 may be of = interest too... =20 David