determining if a int is a power

Graham Klyne GK at
Sun Nov 9 12:52:29 EST 2003

It seems to me that a neater approach might be to create a list of powers 
(squares) and see if it has any members in common with the list supplied.

Of course you have to deal with the issue of not knowing in advance how 
many members of the list of squares will be needed... which can lead to 
using some rather interesting features of Haskell.


At 23:46 07/11/03 +0100, ddekker6 at wrote:
>hello all,
>im new to haskell and have to do some excersises. Well i ran into this 
>problem. I have to determin if a list of int's contains a int that is a 
>power. So i have been trying using "any" with a helper function which 
>return a Bool if the int is a power and applying that to the list. I think 
>that this aproach should work.
>Anyway the problem im having is in the helper function. I have been trying 
>isPower n =
>         let powerF = floor(sqrt(n)) in
>         if (powerF*PowerF == n)
>                 then True
>                 else False
>but this doesnt work. Prelude says that the definition of isPower needs a 
>fractional int (if i remember correctly)  anyway it looks like something 
>is wrong with my type's? Could you guys help me out? Is there a simple 
>standard function i overlooked. Or what should i change? Thanks in advance 
>Haskell-Cafe mailing list
>Haskell-Cafe at

Graham Klyne
For email:

More information about the Haskell-Cafe mailing list