Skip to content

Instantly share code, notes, and snippets.

@thomwiggers
Created October 20, 2012 14:14
Show Gist options
  • Save thomwiggers/3923394 to your computer and use it in GitHub Desktop.
Save thomwiggers/3923394 to your computer and use it in GitHub Desktop.
is_sorted :: Ord a => Tree a -> Bool
is_sorted Leaf = True
is_sorted (Node e left right)
-- de richting van <= en > is andersom, want prefixnotatie
= is_sorted' ((>=) e) left && is_sorted' ((<) e) right
where
is_sorted' :: Ord a => (a->Bool) -> Tree a -> Bool
is_sorted' _ Leaf = True
is_sorted' test (Node e left right)
| test e == False = False
| otherwise = is_sorted left && is_sorted right
&& is_sorted' test left && is_sorted' test right
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment