Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] infinity matches all
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Mattias Waldau <mattias.waldau@a...>
Subject: Re: [Caml-list] infinity matches all
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