### Palindromes again?

Actually, it's more Haskell than palindromes.

I've been looking over other people's solutions to the "Fair and Square" problem, and they are pretty impressive. As a still-inexperienced Haskeller, I am taking inspiration from then rather than feeling discouraged.

In particular, jagd's solution reminded me that I was not thinking Haskell. Haskell is lazy; values aren't calculated until you require them. That lets you define infinite data structures! You only get into trouble if you do something that requires the whole thing.

For example,

and then ask for

you will get back 1, 2, 3, 4, and 5, and then the function call will hang. You and I realize that

I've been looking over other people's solutions to the "Fair and Square" problem, and they are pretty impressive. As a still-inexperienced Haskeller, I am taking inspiration from then rather than feeling discouraged.

In particular, jagd's solution reminded me that I was not thinking Haskell. Haskell is lazy; values aren't calculated until you require them. That lets you define infinite data structures! You only get into trouble if you do something that requires the whole thing.

For example,

**[1..]**is the infinite list of all positive integers. You can safely use it, as long as you only use a finite amount of it. For example, if you try**uptoSqrt n = [x | x <- [1..], x * x <= n]**and then ask for

**uptoSqrt 25**you will get back 1, 2, 3, 4, and 5, and then the function call will hang. You and I realize that

**\x -> x * x**is monotonically increasing for positive numbers, but Haskell doesn't, and obligingly t…