Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] infinity matches all
> 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 Archives:
Bug reports: FAQ:
Beginner's list: