我正在尝试编写一个函数,给定两个表示图像的四叉树,将输出另一个布尔四叉树“掩码”,True
如果两个四叉树在相应位置具有相同的颜色,则具有像素值,False
否则。
我收到此错误:
Occurs check: cannot construct the infinite type: a = QT a
Expected type: QT (QT a)
Inferred type: QT a
In the second argument of `mask', namely `c2'
In the first argument of `Q', namely `(mask a c2)'
并且无法理解为什么。功能是:
data (Eq a, Show a) => QT a = C a | Q (QT a) (QT a) (QT a) (QT a)
deriving (Eq, Show)
mask :: (Eq a, Show a) => QT a -> QT a -> QT Bool
mask q1 q2 = m q1 q2
where
m (C c1) (C c2) = C (c1 == c2)
m (Q (C a) (C b) (C c) (C d)) (Q (C e) (C f) (C g) (C h))
| and $ zipWith (==) [a, b, c, d] [e, f, g, h] = C True
| otherwise = Q (mask a e) (mask b f) (mask c g) (mask d f)
m (Q a b c d) (C c2) = Q (mask a c2) (mask b c2) (mask c c2) (mask d c2)
m c@(C _) q@(Q _ _ _ _) = mask q c
m (Q a b c d) (Q e f g h) = Q (mask a e) (mask b f) (mask c g) (mask d h)