Cartesian Plane

Posted by NuNu on Stack Overflow See other posts from Stack Overflow or by NuNu
Published on 2012-10-01T03:35:02Z Indexed on 2012/10/01 3:37 UTC
Read the original article Hit count: 147

I'm trying to define a function in Haskell that takes an integer argument c and returns the list of all points on the cartesian plane of the form (x/c,y/c) where x and y are integers. x/c is between -2 and 1 and y/r is between -1 and 1

This is what I've gotten so far which I'm almost sure is right but I'm getting a parse error on input = when I run it particularly at this line: cart xs ys c = [(y/c,x/c) | x <- xs, y <- ys]

plane :: Int -> [a]
plane c = cart [-1*c .. 1*c] [-2*c .. 1*c] c
     cart xs ys c = [(y/c,x/c) | x <- xs, y <- ys]

A sample output would be: plane 1 would generate:

[(-2.0, -1.0), (-1.0, -1.0), ( 0.0, -1.0), ( 1.0, -1.0),
 (-2.0,  0.0), (-1.0,  0.0), ( 0.0,  0.0), ( 1.0,  0.0),
 (-2.0,  1.0), (-1.0,  1.0), ( 0.0,  1.0), ( 1.0,  1.0)]

Anyone have any idea how I can fix this! Thanks

© Stack Overflow or respective owner

Related posts about haskell

Related posts about functional-programming