"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.


-- 
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited. 

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to