Straight to the point, the type declarations are as follow;
type Pnt = (Int, Int)
type Image = Array Point Int
type Pixels = [Int]
type Dims = (Int, Int)
type Block = (Point,Pixels)
What am trying to do is to get an Image, and from that image obtain a particular block of pixels at position Pnt with a width and length Dims. When working with only one point is fine, no problems or whatsoever;
takeAblock :: Image -> Dims -> Pnt -> Block
takeAblock i (w,h) (x,y) = ((x,y), [i!(u,v) | v <-[y..y + h - 1], u <- [x..x + w - 1]])
However when trying to get multiple points I'm finding myself stuck on how what I believed to be a correct implementation, however the compiler does not seem to agree with me
takeManyBlocks :: Image -> Dims -> [Pnt] -> [Block]
takeManyBlocks i d ps = takeAblock i d (map ps)
where ps (x,y) = x // Error
And the error is the following:
Couldn't match expected type `Pnt' against inferred type `[(t, t1)] -> [t]' In the third argument of `takeAblock', namely `(map ps)' In the expression: takeAblock i d (map ps) In the definition of `takeAblock': takeAblock i d ps = takeAblock i d (map ps) where ps (x, y) = x
I really cant understand why this is not working, I even tried map (*1) ps to check whether the lack of a stated function was the problem, but nothing, the compile error remains the same. Where am I going wrong?
takeManyBlocksargument is namedpsin addition to the where clause definingps). This makes it hard to even talk about what you are doing. Use warnings on the compiler to bring these things to your attention.