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?
The lack of the function is indeed the problem, but not the way you seem to think; something like
map (*1) psis a no-op (forpsa list of numbers, at least). What you really want is something along the lines ofmap (takeAblock i d) ps; the thing you want to map over the list is the first parameter tomap, not sitting somewhere on the other side of it.