[Haskell-cafe] Problems with square root...

Jon Fairbairn Jon.Fairbairn at cl.cam.ac.uk
Wed Dec 21 13:16:53 EST 2005


On 2005-12-21 at 18:10GMT Daniel Carrera wrote:
> Daniel Carrera wrote:
> > Hey,
> > 
> > The sqrt function is not doing what I want. This is what I want:
> > 
> > round sqrt(2)
> 
> Sigh... never fails. Spend an hour trying to solve a problem, and a 
> minute after you write to the list you find the solution. I need 
> brackets around sqrt. I'm surprised though. I don't understand why it 
> dosn't work without brackets.

Elementary syntax. Function application needs no parentheses
and associates left, so

   sqrt 2

is fine, and what you wrote means

  (round sqrt) 2

whereas what you want is

   round (sqrt 2)


-- 
Jón Fairbairn                              Jon.Fairbairn at cl.cam.ac.uk




More information about the Haskell-Cafe mailing list