Associated issue: Binary Search Tree: add test cases for `bstRight`, `bstLeft` · Issue #1142 · exercism/haskell · GitHub
Many, many students write code like
bstLeft :: BST a -> Maybe (BST a) bstLeft (Node _ Nil _) = Nothing bstLeft (Node _ l _) = Just l bstLeft _ = Nothing
I get where this comes from ‐ conflating different kinds of
nulls – but in Haskell this is morally wrong: it should be simply
bstLeft :: BST a -> Maybe (BST a) bstLeft (Node _ l _) = Just l bstLeft _ = Nothing
as empty trees are trees still.
The current tests do not catch this. I propose to add tests that do.
A quick look at the problem specification suggests to me that it cannot express this distinction. I could be wrong though. For the moment I’m only proposing to add these tests to the Haskell (family) track(s).
_ = do let t = singleton 4 bstLeft t `shouldNotBe` Nothing bstRight t `shouldNotBe` Nothing