Re: [Haskell-cafe] How to decide if a number is an integer?

2009-09-29 Thread Jimmy Hartzell
Use properFraction: http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v%3AproperFraction Hi, In other weak-type language, `round i == i` would work. But in haskell, what should I do? Thanks. -- 竹密岂妨流水过 山高哪阻野云飞

Re: [Haskell-cafe] How to decide if a number is an integer?

2009-09-29 Thread Magicloud Magiclouds
It never matches to (_, 0.0) I mean case properFraction l of (_, 0) - l _ - 0 -- always goes here. On Tue, Sep 29, 2009 at 2:18 PM, Jimmy Hartzell j...@shareyourgifts.net wrote: Use properFraction: http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v%3AproperFraction

Re: [Haskell-cafe] How to decide if a number is an integer?

2009-09-29 Thread Thomas DuBuisson
On Mon, Sep 28, 2009 at 11:35 PM, Magicloud Magiclouds magicloud.magiclo...@gmail.com wrote: It never matches to (_, 0.0) I mean case properFraction l of (_, 0) - l _ - 0 -- always goes here. Odd, it works fine for me. f x = case properFraction x of (_,0) -

Re: [Haskell-cafe] How to decide if a number is an integer?

2009-09-29 Thread Jimmy Hartzell
$ ghci Prelude let isInteger' l = case properFraction l of { (_,0) - 1; _ - 0 } Prelude isInteger' 2.0 1 Prelude isInteger' 1.9 0 Do you really get 1? For what input types/values? Although I would write: isInteger = (== 0) . snd . properFraction It never matches to (_, 0.0) I mean case

Re: [Haskell-cafe] How to decide if a number is an integer?

2009-09-29 Thread Magicloud Magiclouds
The original code is givenSum num = map (\a - let l = (sqrt $ fromIntegral (a * a + 2 + 2 * num)) - (fromIntegral a) in case properFraction l of (_, 0) - True _ -

Re: [Haskell-cafe] How to decide if a number is an integer?

2009-09-29 Thread Thomas DuBuisson
Unless I missed something, the function in question is: sqrt (a * a + 2 + 2 * num) - fromIntegral a where num = 10 1 - sqrt (1 * 1 + 2 + 2 * 10) - 1 - sqrt (1 + 2 + 20) - 1 - sqrt (23) - 1 - 3.79x the fractional will only ever come from the sqrt function. Do any of the following actually

Re: [Haskell-cafe] How to decide if a number is an integer?

2009-09-29 Thread Jimmy Hartzell
Did you test the properFraction-based code in isolation? If code is broken, it's important to figure out which part of it is broken. Also, this function is not divided into constituent parts, but is a long unruly mess. Dividing it into parts would make it much much more readable, and you would

Re: [Haskell-cafe] How to decide if a number is an integer?

2009-09-29 Thread Magicloud Magiclouds
Of course them are not. But that is why I need the detector 2009/9/29 Thomas DuBuisson thomas.dubuis...@gmail.com: Unless I missed something, the function in question is: sqrt (a * a + 2 + 2 * num) - fromIntegral a where num = 10 1 - sqrt (1 * 1 + 2 + 2 * 10) - 1 - sqrt (1 + 2 + 20) - 1

Re: [Haskell-cafe] How to decide if a number is an integer?

2009-09-29 Thread Magicloud Magiclouds
The properFaction part is correct. So I posted the whole code, since isInteger should accept any reasonable incoming types. Well, in this one situation, it does not. And I cannot figure out why On Tue, Sep 29, 2009 at 3:07 PM, Jimmy Hartzell j...@shareyourgifts.net wrote: Did you test the

Re: [Haskell-cafe] How to decide if a number is an integer?

2009-09-29 Thread david48
On Tue, Sep 29, 2009 at 9:13 AM, Magicloud Magiclouds magicloud.magiclo...@gmail.com wrote: The properFaction part is correct. So I posted the whole code, since isInteger should accept any reasonable incoming types. Well, in this one situation, it does not. And I cannot figure out why

Re: [Haskell-cafe] How to decide if a number is an integer?

2009-09-29 Thread Jimmy Hartzell
*Should* isInteger be returning True for any numbers generated by this code? If so, can you simplify this test down to that example, so that it's obvious what the test should do, and that it's not doing it (if it in fact is not doing as it should)? In any case, it would help to divide this block

Re: [Haskell-cafe] How to decide if a number is an integer?

2009-09-29 Thread Magicloud Magiclouds
Resolved. As Thomas said, mixing up sure is a bad thing. But then I have to name so many meanless (at least I think) computing process On Tue, Sep 29, 2009 at 3:32 PM, Jimmy Hartzell j...@shareyourgifts.net wrote: *Should* isInteger be returning True for any numbers generated by this code?  

Re: [Haskell-cafe] How to decide if a number is an integer?

2009-09-29 Thread Luke Palmer
On Tue, Sep 29, 2009 at 2:30 AM, Magicloud Magiclouds magicloud.magiclo...@gmail.com wrote: Resolved. As Thomas said, mixing up sure is a bad thing. But then I have to name so many meanless (at least I think) computing process That is the primary challenge of writing readable code:

Re: [Haskell-cafe] How to decide if a number is an integer?

2009-09-29 Thread Daniel Fischer
Am Dienstag 29 September 2009 09:02:19 schrieb Thomas DuBuisson: Unless I missed something, the function in question is: sqrt (a * a + 2 + 2 * num) - fromIntegral a where num = 10 1 - sqrt (1 * 1 + 2 + 2 * 10) - 1 - sqrt (1 + 2 + 20) - 1 - sqrt (23) - 1 - 3.79x the fractional will

Re: [Haskell-cafe] How to decide if a number is an integer?

2009-09-29 Thread Henning Thielemann
On Tue, 29 Sep 2009, Magicloud Magiclouds wrote: Hi, In other weak-type language, `round i == i` would work. But in haskell, what should I do? Thanks. Am I right, that you want to check whether a number is a square number? http://www.haskell.org/haskellwiki/Generic_number_type#isSquare

[Haskell-cafe] How to decide if a number is an integer?

2009-09-28 Thread Magicloud Magiclouds
Hi, In other weak-type language, `round i == i` would work. But in haskell, what should I do? Thanks. -- 竹密岂妨流水过 山高哪阻野云飞 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe