caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] exceptions and the polymorphic equality
@ 2001-07-15 13:05 eijiro_sumii
  2001-07-16 14:44 ` Nils Goesche
  2001-07-16 15:11 ` Pierre Weis
  0 siblings, 2 replies; 10+ messages in thread
From: eijiro_sumii @ 2001-07-15 13:05 UTC (permalink / raw)
  To: caml-list; +Cc: sumii

Hello,

I have a question about the polymorphic equality and exceptions: it
seems to me that the behaviour of "=" is counter-intuitive with
respect to pattern matching of exceptions, for example as follows.

        Objective Caml version 3.01

# exception Foo;;
exception Foo
# let e = Foo;;
val e : exn = Foo
# exception Foo;;
exception Foo
# let e' = Foo;;
val e' : exn = Foo
# e = e';;
- : bool = true
# match e with Foo -> true | _ -> false;;
- : bool = false
# try raise e with Foo -> ();;
Uncaught exception: Foo.
# 

I know that the two Foo's above should be distinct, but then shouldn't
e = e' also return false?  Is this issue well known?

	Eijiro
-------------------
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


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

* Re: [Caml-list] exceptions and the polymorphic equality
  2001-07-15 13:05 [Caml-list] exceptions and the polymorphic equality eijiro_sumii
@ 2001-07-16 14:44 ` Nils Goesche
  2001-07-16 14:58   ` Xavier Urbain
  2001-07-16 15:11 ` Pierre Weis
  1 sibling, 1 reply; 10+ messages in thread
From: Nils Goesche @ 2001-07-16 14:44 UTC (permalink / raw)
  To: caml-list

eijiro_sumii@anet.ne.jp writes:

> I have a question about the polymorphic equality and exceptions: it
> seems to me that the behaviour of "=" is counter-intuitive with
> respect to pattern matching of exceptions, for example as follows.
> 
>         Objective Caml version 3.01
> 
> # exception Foo;;
> exception Foo
> # let e = Foo;;
> val e : exn = Foo
> # exception Foo;;
> exception Foo
> # let e' = Foo;;
> val e' : exn = Foo
> # e = e';;
> - : bool = true
> # match e with Foo -> true | _ -> false;;
> - : bool = false
> # try raise e with Foo -> ();;
> Uncaught exception: Foo.
> # 
> 
> I know that the two Foo's above should be distinct, but then shouldn't
> e = e' also return false?  Is this issue well known?

I can't see any ``issue'' here:

# e == e';;
- : bool = false

# try raise e with e -> ();;
- : unit = ()

Isn't that just fine?

Regards,
-- 
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x42B32FC9

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


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

* Re: [Caml-list] exceptions and the polymorphic equality
  2001-07-16 14:44 ` Nils Goesche
@ 2001-07-16 14:58   ` Xavier Urbain
  2001-07-16 15:02     ` Xavier Urbain
  0 siblings, 1 reply; 10+ messages in thread
From: Xavier Urbain @ 2001-07-16 14:58 UTC (permalink / raw)
  To: Nils Goesche; +Cc: caml-list

On  July 16, 2001, Nils Goesche wrote: 

 > # e == e';;
 > - : bool = false
 > 
 > # try raise e with e -> ();;
 > - : unit = ()
 > 
 > Isn't that just fine?
 > 

Indeed but the fact that Foo was defined twice makes 
# e = e' 
- : bool = false
look weird. 


Xavier Urbain		
---------------------------------------------------------------
L.R.I., Bât 490                    mailto: Xavier.Urbain@lri.fr
Université de Paris-Sud            phoneto:  (33) 1 69 15 42 32
F-91405 Orsay cedex                faxto:    (33) 1 69 15 65 86

     http://www.lri.fr/demons/urbain/introduction.fr.html
---------------------------------------------------------------
-------------------
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


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

* Re: [Caml-list] exceptions and the polymorphic equality
  2001-07-16 14:58   ` Xavier Urbain
@ 2001-07-16 15:02     ` Xavier Urbain
  2001-07-16 15:58       ` Nils Goesche
  0 siblings, 1 reply; 10+ messages in thread
From: Xavier Urbain @ 2001-07-16 15:02 UTC (permalink / raw)
  To: Nils Goesche, caml-list

On Monday July 16, 2001, Xavier Urbain wrote: 
 > # e = e' 
 > - : bool = false
 > look weird. 

My mistake, I meant
 # e = e' 
 - : bool = true
 look weird.


Xavier Urbain		
---------------------------------------------------------------
L.R.I., Bât 490                    mailto: Xavier.Urbain@lri.fr
Université de Paris-Sud            phoneto:  (33) 1 69 15 42 32
F-91405 Orsay cedex                faxto:    (33) 1 69 15 65 86

     http://www.lri.fr/demons/urbain/introduction.fr.html
---------------------------------------------------------------
-------------------
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


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

* Re: [Caml-list] exceptions and the polymorphic equality
  2001-07-15 13:05 [Caml-list] exceptions and the polymorphic equality eijiro_sumii
  2001-07-16 14:44 ` Nils Goesche
@ 2001-07-16 15:11 ` Pierre Weis
  2001-07-17  0:59   ` eijiro_sumii
  1 sibling, 1 reply; 10+ messages in thread
From: Pierre Weis @ 2001-07-16 15:11 UTC (permalink / raw)
  To: eijiro_sumii; +Cc: caml-list

> Hello,
> 
> I have a question about the polymorphic equality and exceptions: it
> seems to me that the behaviour of "=" is counter-intuitive with
> respect to pattern matching of exceptions, for example as follows.

Exception definitions are generative in Caml: it means that the
definition of two exceptions with the same names generate two
different exceptions that are not confused by the language. It is
similar to type definitions, and constructors for sum type.

On the other hand, the structural equality (=) when applied to
exceptions and constructors is not completely specified, hence
unreliable. 

Hence:

>         Objective Caml version 3.01
> 
> # exception Foo;;
> exception Foo
> # let e = Foo;;
> val e : exn = Foo
> # exception Foo;;
> exception Foo

This (new) exception Foo is different from the preceding (old) one:
the language will not confuse them.

> # let e' = Foo;;
> val e' : exn = Foo
> # e = e';;
> - : bool = true

Here, you learn that (old) Foo and (new) Foo are structurally
equivalent, i.e. represented by equivalent Caml values (e.g. the same
string).

> # match e with Foo -> true | _ -> false;;
> - : bool = false

Yes, (old) Foo is not confused with (new) Foo.

> # try raise e with Foo -> ();;
> Uncaught exception: Foo.

Once more the two exceptions are not confused.

> I know that the two Foo's above should be distinct, but then shouldn't
> e = e' also return false?  Is this issue well known?

You're right, having e <> e' should be desirable. However, in this
case you should not test structural equality, since it is very likely
the case that e and e' are represented by the same kind of value. You
should test identity (==) instead:

# e == e';;
- : bool = false

That's what the compiler generates when pattern matching exception
values (more precisely it uses == for the exception constructor and
regular pattern matching for the rest of the pattern).

Hope this helps,

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/


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


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

* Re: [Caml-list] exceptions and the polymorphic equality
  2001-07-16 15:02     ` Xavier Urbain
@ 2001-07-16 15:58       ` Nils Goesche
  0 siblings, 0 replies; 10+ messages in thread
From: Nils Goesche @ 2001-07-16 15:58 UTC (permalink / raw)
  To: caml-list

Xavier Urbain <Xavier.Urbain@lri.fr> writes:

> On Monday July 16, 2001, Xavier Urbain wrote: 
>  > # e = e' 
>  > - : bool = false
>  > look weird. 
> 
> My mistake, I meant
>  # e = e' 
>  - : bool = true
>  look weird.

I guess I had too much exposure to Common Lisp with all those eq, equ,
equal, equalp, =, string= and God knows what operators :-)
-- 
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x42B32FC9

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


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

* Re: [Caml-list] exceptions and the polymorphic equality
  2001-07-16 15:11 ` Pierre Weis
@ 2001-07-17  0:59   ` eijiro_sumii
  2001-07-17 14:35     ` Nils Goesche
  0 siblings, 1 reply; 10+ messages in thread
From: eijiro_sumii @ 2001-07-17  0:59 UTC (permalink / raw)
  To: caml-list; +Cc: Pierre.Weis, sumii

> On the other hand, the structural equality (=) when applied to
> exceptions and constructors is not completely specified, hence
> unreliable. 

I see, this makes sense - indeed, exn is not an equality type in SML.

> You're right, having e <> e' should be desirable. However, in this
> case you should not test structural equality, since it is very likely
> the case that e and e' are represented by the same kind of value. You
> should test identity (==) instead:
> 
> # e == e';;
> - : bool = false
> 
> That's what the compiler generates when pattern matching exception
> values (more precisely it uses == for the exception constructor and
> regular pattern matching for the rest of the pattern).

Several people have suggested using == instead of =, but doing so
seems even more problematic because:

        Objective Caml version 3.01

# exception Foo;;
exception Foo
# Foo == Foo;;
- : bool = false
# 

Regards,

	Eijiro
-------------------
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


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

* Re: [Caml-list] exceptions and the polymorphic equality
  2001-07-17  0:59   ` eijiro_sumii
@ 2001-07-17 14:35     ` Nils Goesche
  2001-07-18  0:28       ` eijiro_sumii
  0 siblings, 1 reply; 10+ messages in thread
From: Nils Goesche @ 2001-07-17 14:35 UTC (permalink / raw)
  To: caml-list

eijiro_sumii@anet.ne.jp writes:

> > On the other hand, the structural equality (=) when applied to
> > exceptions and constructors is not completely specified, hence
> > unreliable. 
> 
> I see, this makes sense - indeed, exn is not an equality type in SML.
> 
> > You're right, having e <> e' should be desirable. However, in this
> > case you should not test structural equality, since it is very likely
> > the case that e and e' are represented by the same kind of value. You
> > should test identity (==) instead:
> > 
> > # e == e';;
> > - : bool = false
> > 
> > That's what the compiler generates when pattern matching exception
> > values (more precisely it uses == for the exception constructor and
> > regular pattern matching for the rest of the pattern).
> 
> Several people have suggested using == instead of =, but doing so
> seems even more problematic because:
> 
>         Objective Caml version 3.01
> 
> # exception Foo;;
> exception Foo
> # Foo == Foo;;
> - : bool = false
> # 

Hm, strange :-) Apparently, `Foo' is a constant constructor, and it
should work like this:

# type bingo = Bingo | Bongo;;
type bingo = Bingo | Bongo
# Bingo == Bingo;;
- : bool = true

OTOH, we also have

# 2 == 2;;
- : bool = true
# 2.0 == 2.0;;
- : bool = false

So, this still doesn't seem like a bug to me...

Regards,
-- 
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x42B32FC9

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


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

* Re: [Caml-list] exceptions and the polymorphic equality
  2001-07-17 14:35     ` Nils Goesche
@ 2001-07-18  0:28       ` eijiro_sumii
  2001-07-18 13:36         ` Nils Goesche
  0 siblings, 1 reply; 10+ messages in thread
From: eijiro_sumii @ 2001-07-18  0:28 UTC (permalink / raw)
  To: caml-list; +Cc: cartan, sumii

From: Nils Goesche <cartan@cartan.de>
> I can't see any ``issue'' here:
> 
> # e == e';;
> - : bool = false
> 
> # try raise e with e -> ();;
> - : unit = ()

Is this a kind of sophisticated joke or something?:-) It catches _any_
exception.

From: Nils Goesche <cartan@cartan.de>
> OTOH, we also have
> 
> # 2 == 2;;
> - : bool = true
> # 2.0 == 2.0;;
> - : bool = false
> 
> So, this still doesn't seem like a bug to me...

I've never said or even thought that "Foo == Foo" being false is a
bug; it just implies that constant exceptions are not "simple
single-word" objects (like integers and constant constructors) in
OCaml, I suppose, as floats are not.

	Eijiro
-------------------
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


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

* Re: [Caml-list] exceptions and the polymorphic equality
  2001-07-18  0:28       ` eijiro_sumii
@ 2001-07-18 13:36         ` Nils Goesche
  0 siblings, 0 replies; 10+ messages in thread
From: Nils Goesche @ 2001-07-18 13:36 UTC (permalink / raw)
  To: caml-list

eijiro_sumii@anet.ne.jp writes:

> From: Nils Goesche <cartan@cartan.de>
> > I can't see any ``issue'' here:
> > 
> > # e == e';;
> > - : bool = false
> > 
> > # try raise e with e -> ();;
> > - : unit = ()
> 
> Is this a kind of sophisticated joke or something?:-) It catches _any_
> exception.

>From which it follows as sure as hell that it'll catch the one you
wanted to catch, right?

Okok, I goofed, forget about it :-)

> From: Nils Goesche <cartan@cartan.de>
> > OTOH, we also have
> > 
> > # 2 == 2;;
> > - : bool = true
> > # 2.0 == 2.0;;
> > - : bool = false
> > 
> > So, this still doesn't seem like a bug to me...
> 
> I've never said or even thought that "Foo == Foo" being false is a
> bug; it just implies that constant exceptions are not "simple
> single-word" objects (like integers and constant constructors) in
> OCaml, I suppose, as floats are not.

Apparently.

Regards,
-- 
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x42B32FC9

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


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

end of thread, other threads:[~2001-07-18 13:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-15 13:05 [Caml-list] exceptions and the polymorphic equality eijiro_sumii
2001-07-16 14:44 ` Nils Goesche
2001-07-16 14:58   ` Xavier Urbain
2001-07-16 15:02     ` Xavier Urbain
2001-07-16 15:58       ` Nils Goesche
2001-07-16 15:11 ` Pierre Weis
2001-07-17  0:59   ` eijiro_sumii
2001-07-17 14:35     ` Nils Goesche
2001-07-18  0:28       ` eijiro_sumii
2001-07-18 13:36         ` Nils Goesche

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