
Hi,All! I find out that diff between GHC and Hugs: GHC: *Prelude> sqrt 3+4+9 14.732050807568877 Prelude> sqrt 16 4.0 Prelude> sqrt $3+4+9 14.732050807568877* Hugs:*Hugs> sqrt $ 3+4+9* *4.0* *Hugs> sqrt 3+4+9* *14.7320508075689* Which one is right? Thanks. -- Regards, Linker Lin linker.m.lin@gmail.com

Sorry.I defined a function :
*GHCi, version 6.10.3: http://www.haskell.org/ghc/ :? for help*
*Loading package ghc-prim ... linking ... done.*
*Loading package integer ... linking ... done.*
*Loading package base ... linking ... done.*
*Prelude> sqrt $ 3 + 4 + 9*
*4.0*
*Prelude> let f $ x = f x*
*Prelude> sqrt $ 3 + 4 + 9*
*14.732050807568877*
*Prelude>*
On Mon, Jul 27, 2009 at 10:50, Linker
Hi,All! I find out that diff between GHC and Hugs: GHC:
*Prelude> sqrt 3+4+9 14.732050807568877 Prelude> sqrt 16 4.0 Prelude> sqrt $3+4+9 14.732050807568877*
Hugs: *Hugs> sqrt $ 3+4+9* *4.0* *Hugs> sqrt 3+4+9* *14.7320508075689*
Which one is right? Thanks.
-- Regards, Linker Lin linker.m.lin@gmail.com
-- Regards, Linker Lin linker.m.lin@gmail.com

On Sunday 26 July 2009 10:54:53 pm Linker wrote:
Sorry.I defined a function :
*GHCi, version 6.10.3: http://www.haskell.org/ghc/ :? for help* *Loading package ghc-prim ... linking ... done.* *Loading package integer ... linking ... done.* *Loading package base ... linking ... done.* *Prelude> sqrt $ 3 + 4 + 9* *4.0* *Prelude> let f $ x = f x* *Prelude> sqrt $ 3 + 4 + 9* *14.732050807568877* *Prelude>*
Unless otherwise specified, operators receive precedence (I think) infixl 9. The ($) in the prelude is infixr 0, so sqrt $ 3 + 4 + 9 = sqrt (3 + 4 + 9) When you define your own ($) in that session, you don't give a corresponding fixity declaration, so infixl 9 is assumed. Thus your second expression parses thusly: sqrt $ 3 + 4 + 9 = (sqrt 3) + 4 + 9 You can give fixity declarations in lets and wheres, so: let infixr 0 $ ; f $ x = f x should act the same as the prelude-defined operator. -- Dan
participants (2)
-
Dan Doel
-
Linker