On Sat, 12 Jan 2008, Achim Schneider wrote: > "Rafael Almeida" <[EMAIL PROTECTED]> wrote: > > > perfectSquares :: [Integer] > > perfectSquares = zipWith (*) [1..] [1..] > > > isPerfectSquare :: Integer -> Bool > > isPerfectSquare x = (head $ dropWhile (<x) perfectSquares) == x > > what about > > module Main where > > isPerfectSquare :: Integer -> Bool > isPerfectSquare n = sqrrt == fromIntegral (truncate sqrrt) > where sqrrt = sqrt $ fromIntegral n > > ? It's a hell alot faster, but I have no idea if some numerical > property of square roots could make it give different results than your > version, in rare cases.
The rare cases occur for big numbers. http://www.haskell.org/haskellwiki/Generic_number_type#isSquare _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
