The 'gridList' function description:
Takes two Integer inputs,
x and y, and returns a list of tuples representing the coordinates
of each cell from (1,1) to (x,y).
Example Output
$> gridList 3 3
$> [(1,1),(2,1),(3,1),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)]
Source Code
gridList :: Integer -> Integer -> [(Integer,Integer)]
gridList 1 1 = [(1,1)]
gridList 1 y = helper 1 y
gridList x y = (helper x y) ++ gridList (x-1) y
where
helper :: Integer -> Integer -> [(Integer, Integer)]
helper x 1 = [(x,1)]
helper x y = (x,y) : (helper x (y-1))
Question: The code doesn't compile giving the following error: Variable not in scope
referring to the line 3 where the helper is first introduced. Why doesn't the wheresolve this problem?
Thanks
whereis just the single definition (equals sign) above it. You need to either pull the helper out of the where, or convert the main gridList patterns into another helper.gridListwon't produce the pairs in the order you expect.