Created
December 17, 2014 03:21
-
-
Save JustinSDK/8c1b0b1d9eed3249a7ad to your computer and use it in GitHub Desktop.
〈Haskell Tutorial(14)減輕型態負擔的型態參數〉的答案
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 Map k v = Empty | Cm (k, v) (Map k v) | |
fromList :: [(k, v)] -> Map k v | |
fromList [] = Empty | |
fromList (x:xs) = Cm x (fromList xs) | |
findValue :: (Eq k) => k -> Map k v -> Maybe v | |
findValue key Empty = Nothing | |
findValue key (Cm (k, v) xm) = | |
if key == k then Just v else findValue key xm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment