Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] function type confusion (using let)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: ITO Tsuyoshi <tsuyoshi@i...>
Subject: Re: [Caml-list] function type confusion (using let)
From: Michael Leary <leary@nwlink.com>
Subject: Re: [Caml-list] function type confusion (using let)
Date: Sun, 2 Sep 2001 22:51:40 -0700
Message-ID: <20010902225140.A22597@ip178.usw22.rb1.bel.nwlink.com>

> Well, this compiles, but looks funny:
> 
> let normr r =
>   let x = mod_float r pi2 in
>   match x > 0.0 with
>   | true ->
>       if x > pi then
>         -.pi2 +. x
>       else
>         x
>   | false ->
>       if x < -.pi then
>         pi2 +. x
>       else
>         x
> 
> Is there a different way?

I'm not sure if I got what you mean correctly, but I think you can
write:
    let normr r =
      let x = mod_float r pi2 in
      if x > 0.0 then begin
        if x > pi then
          -.pi2 +. x
        else
          x
      end
      else begin
        if x < -.pi then
          pi2 +. x
        else
          x
      end

(Two begin-end pairs are not necessary in the code above but they are
 for readability; in case you are confused by them, just ignore them.)

Of course you can write it in a more straightforward way if you don't
care the order of the tests....
    let normr r =
      let x = mod_float r pi2 in
      if x > pi then
        -.pi2 +. x
      else if x >= -.pi then
        x
      else
        pi2 +. x

-- ITO Tsuyoshi  <tsuyoshi@is.s.u-tokyo.ac.jp> --
-------------------
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