True画像を表す2つの四分木が与えられた場合、両方の四分木が同じ色で対応する位置にある場合はピクセルの値を使用して、別のブール四分木「マスク」を出力する関数を作成しようとしてい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)