Skip to content

Instantly share code, notes, and snippets.

@hamishdickson
Created March 6, 2017 17:30
Show Gist options
  • Save hamishdickson/115fedb88447fa624347e57cb1b1f88d to your computer and use it in GitHub Desktop.
Save hamishdickson/115fedb88447fa624347e57cb1b1f88d to your computer and use it in GitHub Desktop.
binary search tree
-- binary search tree
insert : Ord elem => elem -> Tree elem -> Tree elem
insert x Empty = Node Empty x Empty
insert x (Node left val right) = case compare x val of
LT => Node (insert x left) val right
EQ => Node left val right
GT => Node left val (insert x right)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment