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

Tue Sep 29 03:32:54 EDT 2009

```*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 of code into more manageable pieces.

isInteger should have the type Fractional a => a -> Boolean.

> 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 <jim at shareyourgifts.net>
> wrote:
>> 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 then be able to test the parts individually.
>>
>> Jimmy
>>
>>> 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
>>> Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  _ ->
>>> Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  False
>>> Â  Â  Â  Â  Â  Â  Â  Â  Â  Â ) \$ take num [1..]
>>> :t l is (Floating a) => a
>>> Well, in ghci
>>> *Main> givenSum 10
>>> [False,False,False,False,False,False,False,False,False,False]
>>>
>>> On Tue, Sep 29, 2009 at 2:45 PM, Thomas DuBuisson
>>> <thomas.dubuisson at gmail.com> wrote:
>>>> On Mon, Sep 28, 2009 at 11:35 PM, Magicloud Magiclouds
>>>> <magicloud.magiclouds at 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) -> True
>>>> Â  Â  Â  Â  Â  Â  Â  Â _ Â  Â  -> False
>>>>
>>>>
>>>> *Main> f 5
>>>> True
>>>> *Main> f 5.5
>>>> False
>>>> *Main> f 4.0
>>>> True
>>>> *Main> f 4.00000001
>>>> False
>>>>
>>>>
>>>> Thomas
>>>>
>>>
>>>
>>>
>>> --
>>> ç«¹å¯†å²‚å¦¨æµæ°´è¿‡
>>> å±±é«˜å“ªé˜»é‡Žäº‘é£ž
>>>
>>
>>
>>
>
>
>
> --
> ç«¹å¯†å²‚å¦¨æµæ°´è¿‡
> å±±é«˜å“ªé˜»é‡Žäº‘é£ž
>

```