Skip to content

Instantly share code, notes, and snippets.

@zwilias
Created March 21, 2017 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zwilias/d0b27f2b83140aafc83b65bb5489cdf6 to your computer and use it in GitHub Desktop.
Save zwilias/d0b27f2b83140aafc83b65bb5489cdf6 to your computer and use it in GitHub Desktop.
isValidBst : Tree comparable -> Bool
isValidBst tree =
case tree of
Empty ->
True
Node value left right ->
all (\x -> x < value) left
&& all (\x -> x > value) right
&& isValidBst left
&& isValidBst right
all : (comparable -> comparable -> Bool) -> Tree comparable -> Bool
all condition tree =
case tree of
Empty ->
True
Node value left right ->
condition value
&& all condition left
&& all condition right
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment