I would like to write a function in haskell, which checks if a Binarytree with this specific structure:
data BB a = L | K a (BB a) (BB a) deriving Show
is a BinarySearchTree or not. An example for a BinarySearchTree:
baumA = K 5 (K 3 (K 1 L L) L) (K 7 L (K 12 (K 9 L L) L))
The function I wrote works, but gives me some warnings im unclear of why they're appearing. The warnings are:
"Pattern match has inaccessible right hand side In an equation for `hilf': hilf (K w L L) acc 0 = ..."
and
"Pattern match is redundant In an equation for `hilf': hilf (K w L L) acc 1 = ..."
The code for my funciton is this here:
isBinarySearchTree :: Ord a => BB a -> Bool
isBinarySearchTree (K initial l r) = hilf l initial 0 && hilf r initial 1
-- "0" means left side and "1" means right side
hilf L _ _ = True -- neutral case
hilf (K w l r) acc 0
| w < acc && hilf l w 0 && hilf r w 1 = True
| otherwise = False
hilf (K w L L) acc 0
| w < acc = True
| otherwise = False
hilf (K w l r) acc 1
| w > acc && hilf l w 0 && hilf r w 1 = True
| otherwise = False
hilf (K w L L) acc 1
| w > acc = True
| otherwise = False