I have the function pyths:
-- takes an Int and returns a list of pythagorean triples whose components
---- are at most the given Int
pyths :: Int a => a -> [(Int, Int, Int)]
pyths n = [(x, y, z) | x <- f, y <- f, z <- f, x^2 + y^2 == z^2]
where f = factors n
I get the error that factors is out of scope. How can I write this function so it’s in scope?
I’ve tried:
pyths n = [(x, y, z) | x <- f, y <- f, z <- f, x^2 + y^2 == z^2 where f = factors n]
and:
pyths n = [(x, y, z) | x <- f, y <- f, z <- f, x^2 + y^2 == z^2, where f = factors n]
But then I just get syntax errors.
Note:
I know this may not actually do what I intend it to do.
As sepp2k said, you need to define
factors. In your examples you change wherefis defined, which uses factors in its definition, but no where do you say:Since there is no
factorsfunction defined in the Haskell prelude or other base libraries, you must write this yourself. The primes package will be useful to you, I expect.