Haskell:在抽象数据类型上使用map的问题

Pan*_*cos 1 haskell types compiler-errors list map

直截了当,类型声明如下;

type Pnt = (Int, Int)
type Image = Array Point Int
type Pixels = [Int]
type Dims = (Int, Int)
type Block = (Point,Pixels)
Run Code Online (Sandbox Code Playgroud)

我想要做的是获得一个Image,并从该图像获得Pnt具有宽度和长度的位置的特定像素块Dims.只使用一点就可以了,没有任何问题或任何问题;

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]])
Run Code Online (Sandbox Code Playgroud)

然而,当试图获得多个点时,我发现自己陷入了我认为是正确实现的方式,但是编译器似乎并不同意我的看法

takeManyBlocks :: Image -> Dims -> [Pnt] -> [Block]
takeManyBlocks i d ps = takeAblock i d (map ps)
                                        where ps (x,y) = x  // Error
Run Code Online (Sandbox Code Playgroud)

错误如下:

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
Run Code Online (Sandbox Code Playgroud)

我真的不明白为什么这不起作用,我甚map (*1) ps至试图检查缺少一个陈述的函数是否是问题,但没有,编译错误保持不变.我哪里错了?

gee*_*aur 5

缺乏功能确实是问题,但不是你想象的方式; 像是map (*1) ps一个无操作的东西(ps至少是一个数字列表).你真正想要的是什么map (takeAblock i d) ps?你要在列表上映射的东西是第一个参数map,而不是坐在它的另一边.