Created
July 13, 2022 11:16
-
-
Save fortierq/874aae83af27da06448eb738a18e762a to your computer and use it in GitHub Desktop.
bst.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Tree t = E | N (Tree t) t (Tree t) deriving (Show, Eq) | |
get e E = error "get E" | |
get e (N g (k, v) d) | |
| e == k = v | |
| e < k = get e g | |
| otherwise = get e d | |
set k v E = N E (k, v) E | |
set k v (N g (k', v') d) | |
| k == k' = N g (k, v) d | |
| k < k' = N (set k v g) (k', v') d | |
| otherwise = N g (k', v') (set k v d) | |
a = E | |
b = set "a" 1 a | |
c = set "baba" 4 b | |
get "a" c | |
get "baba" c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment