caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] infinity matches all
@ 2003-08-25 14:12 Yaron Minsky
  2003-08-25 14:35 ` Oleg Trott
  2003-08-25 14:44 ` Xavier Leroy
  0 siblings, 2 replies; 4+ messages in thread
From: Yaron Minsky @ 2003-08-25 14:12 UTC (permalink / raw)
  To: caml-list

Can anyone explain the following behavior of match when used with infinity?

# match "foo" with infinity -> "bar";;
- : string = "bar"

This shouldn't even typecheck.  It seems to treat infinity as equivalent
to "_".  This behavior comes up in version 3.06.

Yaron


-------------------
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] infinity matches all
  2003-08-25 14:12 [Caml-list] infinity matches all Yaron Minsky
@ 2003-08-25 14:35 ` Oleg Trott
  2003-08-25 14:44 ` Xavier Leroy
  1 sibling, 0 replies; 4+ messages in thread
From: Oleg Trott @ 2003-08-25 14:35 UTC (permalink / raw)
  To: Yaron Minsky, caml-list

On Monday 25 August 2003 10:12 am, Yaron Minsky wrote:
> Can anyone explain the following behavior of match when used with infinity?
>
> # match "foo" with infinity -> "bar";;
> - : string = "bar"
>
> This shouldn't even typecheck.  It seems to treat infinity as equivalent
> to "_".  This behavior comes up in version 3.06.

This is ugly. The same happens with  `nan' , BTW.

-- 
Oleg Trott <oleg_trott@columbia.edu>

-------------------
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] infinity matches all
  2003-08-25 14:12 [Caml-list] infinity matches all Yaron Minsky
  2003-08-25 14:35 ` Oleg Trott
@ 2003-08-25 14:44 ` Xavier Leroy
  2003-08-25 14:54   ` Mattias Waldau
  1 sibling, 1 reply; 4+ messages in thread
From: Xavier Leroy @ 2003-08-25 14:44 UTC (permalink / raw)
  To: Yaron Minsky; +Cc: caml-list

> Can anyone explain the following behavior of match when used with infinity?
> 
> # match "foo" with infinity -> "bar";;
> - : string = "bar"
> 
> This shouldn't even typecheck.  It seems to treat infinity as equivalent
> to "_".  This behavior comes up in version 3.06.

This is probably in the FAQ somewhere.  What confuses you is that this
occurrence of "infinity" is just a variable that is bound by the
matching; it's not a constructor, and it's not a constant.  Hence, you
code is equivalent (by renaming) to

        match "foo" with s -> "bar";;

and indeed to

        match "foo" with _ -> "bar";;

since _ behaves like a variable that isn't referenced in the r.h.s.

If you intend to match against the value of floating-point infinity, do

        match e with x when x = infinity -> ...

- Xavier Leroy

-------------------
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] infinity matches all
  2003-08-25 14:44 ` Xavier Leroy
@ 2003-08-25 14:54   ` Mattias Waldau
  0 siblings, 0 replies; 4+ messages in thread
From: Mattias Waldau @ 2003-08-25 14:54 UTC (permalink / raw)
  To: Yaron Minsky; +Cc: Xavier Leroy, caml-list

There is a patch which warns for unused variables. Then you would have 
got the message that the variable "infinity" isn't used. It regulary 
finds bugs for me.

-- Mattias

Xavier Leroy wrote:
>>Can anyone explain the following behavior of match when used with infinity?
>>
>># match "foo" with infinity -> "bar";;
>>- : string = "bar"
>>
>>This shouldn't even typecheck.  It seems to treat infinity as equivalent
>>to "_".  This behavior comes up in version 3.06.
> 
> 
> This is probably in the FAQ somewhere.  What confuses you is that this
> occurrence of "infinity" is just a variable that is bound by the
> matching; it's not a constructor, and it's not a constant.  Hence, you
> code is equivalent (by renaming) to
> 
>         match "foo" with s -> "bar";;
> 
> and indeed to
> 
>         match "foo" with _ -> "bar";;
> 
> since _ behaves like a variable that isn't referenced in the r.h.s.
> 
> If you intend to match against the value of floating-point infinity, do
> 
>         match e with x when x = infinity -> ...
> 
> - Xavier Leroy
> 
> -------------------
> 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
> 



-------------------
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:[~2003-08-25 14:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-25 14:12 [Caml-list] infinity matches all Yaron Minsky
2003-08-25 14:35 ` Oleg Trott
2003-08-25 14:44 ` Xavier Leroy
2003-08-25 14:54   ` Mattias Waldau

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