直接点,类型声明如下;Haskell:在抽象数据类型上使用地图的问题
type Pnt = (Int, Int)
type Image = Array Point Int
type Pixels = [Int]
type Dims = (Int, Int)
type Block = (Point,Pixels)
什么我试图做的是让一个Image
,并从该图像在与宽度和长度Dims
位置Pnt
获得像素的特定块。只用一点就好,没有问题或任何问题;
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]])
然而,当试图让多点,我发现自己停留在怎么样我认为是正确执行,但是编译器似乎并没有跟我
takeManyBlocks :: Image -> Dims -> [Pnt] -> [Block]
takeManyBlocks i d ps = takeAblock i d (map ps)
where ps (x,y) = x // Error
而且同意错误是:
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
我真的不能明白为什么牛逼他没有工作,我甚至试图map (*1) ps
来检查是否缺少一个规定的功能是问题,但没有,编译错误保持不变。我哪里错了?
提示:map接受一个函数和一个列表。你通过了什么? Owch,owch owch。 – Mikel 2011-04-03 03:57:07
Owch,owch owch。请勿影响变量名称(注意除了定义'ps'的where子句外,'takeManyBlocks'参数被命名为'ps')。这使得甚至很难谈论你在做什么。在编译器上使用警告以引起您的注意。 – 2011-04-03 04:43:20