[Haskell-cafe] Re: Is a bug?
Dan Doel
dan.doel at gmail.com
Sun Jul 26 23:04:06 EDT 2009
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
More information about the Haskell-Cafe
mailing list