[Haskell-cafe] Problems with square root...
Hey, The sqrt function is not doing what I want. This is what I want: round sqrt(2) The problem is that sqrt() returns a Floating value and round wants a ReacFrac: --//-- *Main round sqrt(2) interactive:1:0: No instances for (RealFrac (a - a), Integral (t - a1)) arising from use of `round' at interactive:1:0-4 Probable fix: add an instance declaration for (RealFrac (a - a), Integral (t - a1)) In the definition of `it': it = round sqrt (2) *Main --//-- I'm trying to figure out how to turn a Float into a RealFrac so I can pass it to 'round'. Any ideas? Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problems with square root...
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. Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problems with square root...
On 12/21/05, Daniel Carrera [EMAIL PROTECTED] wrote: round sqrt(2) I don't understand why it dosn't work without brackets. Function application is left associative in Haskell. -- regards, radu http://rgrig.blogspot.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problems with square root...
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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problems with square root...
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. because x y z parses as (x y) z, so round sqrt 2 parses as (round sqrt) 2 and round sqrt doesn't make sense. x(y) doesn't mean necessarily apply y to x as it does in C. parens only are used as they are in math to separate stuff. -- Hal Daume III | [EMAIL PROTECTED] Arrest this man, he talks in maths. | www.isi.edu/~hdaume ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problems with square root...
Radu Grigore wrote: I don't understand why it dosn't work without brackets. Function application is left associative in Haskell. Ah. I implicitly assumed right-association (it works in Perl ;) ) Thanks. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problems with square root...
On Wed, Dec 21, 2005 at 06:10:56PM +, 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. In Haskell parentheses are not part of function call syntax, unlike many languages like C, Pascal or Java. The role of parentheses in expressions is only for grouping and disambiguation. What you typed is actually equivalent to round sqrt 2 which in turn is equivalent to ((round sqrt) 2) because function application is left-associative. Best regards Tomasz -- I am searching for a programmer who is good at least in some of [Haskell, ML, C++, Linux, FreeBSD, math] for work in Warsaw, Poland ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problems with square root...
nitpicky detail: () - Parenthesis {} - Braces [] - Brackets Sorry to be pedantic, but using the wrong terminology confuses me and I'm sure others as well. On 12/21/05, Daniel Carrera [EMAIL PROTECTED] 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. Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- 50% of marriages today end in divorce, the other 50% end in death. Which would you rather have? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problems with square root...
MG () - Parenthesis MG {} - Braces MG [] - Brackets MG Sorry to be pedantic, but using the wrong terminology confuses me and MG I'm sure others as well. This is true for Haskell, but Daniel is correct if he is calling () Brackets because they are, in British English, right? (Just like '.' is a 'period' in US, but it is a 'full stop' in UK.). Of course, English /= Haskell so in Haskell I guess they are called Parenthesized Expressions (in the Haskell report http://www.haskell.org/onlinereport/exps.html). To be extra pedantic, I would call {} Curly Braces (or Curly Brackets, or squiggly brackets, or squiggles, or ... just use layout and whitespace!) and I would call [] Square Brackets. Then no one gets confused. Cheerio, Jared P.S. IANAA = I am an American, so I could very well be wrong about British English! On 12/21/05, Daniel Carrera [EMAIL PROTECTED] 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. Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- 50% of marriages today end in divorce, the other 50% end in death. Which would you rather have? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- [EMAIL PROTECTED] http://www.updike.org/~jared/ reverse )-: ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problems with square root...
Mark Goldman wrote: nitpicky detail: () - Parenthesis {} - Braces [] - Brackets Sorry to be pedantic, but using the wrong terminology confuses me and I'm sure others as well. Being pedantic can be fun :) The Macquarie Dictionary, which is the official dictionary in Australia, says that () are brackets. It says that they are also called parentheses or a round bracket, if you need to distinguish between them and square brackets [], curly brackets {}, or angle brackets , and the definition for parenthesis is the upright brackets (). Also, I believe, UK English (and International English) uses the term brackets that way, but I'd have to check online to make sure; I don't have a UK dictionary on me right this minute. Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/I am not over-weight, I am under-tall. / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe