I'm trying to write a function that, given two quadtrees representing images, will output another boolean quadtree "mask", with value True
for a pixel if both quadtrees have the same color the corresponding position, and False
otherwise.
I'm getting this error:
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)'
and can't understand why. The function is:
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)
c2
has typea
, but mask wants an argument of typeQT a
. You should use an@
pattern like you do on the line below it:I think the previous line also has the same problem.