Binary Search Tree: add test cases for `bstLeft` etc

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).

Example test:

_ = do
  let t = singleton 4
  bstLeft t `shouldNotBe` Nothing
  bstRight t `shouldNotBe` Nothing

Asking just to be sure: would there be interest in changing the problem-specification so that it can distinguish between empty tree and no element here?

PR submitted: Add test cases for `bstRight`, `bstLeft` by MatthijsBlom · Pull Request #1152 · exercism/haskell · GitHub.

See also the discussion at Binary Search Tree: add test cases for `bstRight`, `bstLeft` · Issue #1142 · exercism/haskell · GitHub.