Skip to content

Instantly share code, notes, and snippets.

@JustinSDK
Created December 17, 2014 03:21
Show Gist options
  • Save JustinSDK/8c1b0b1d9eed3249a7ad to your computer and use it in GitHub Desktop.
Save JustinSDK/8c1b0b1d9eed3249a7ad to your computer and use it in GitHub Desktop.
〈Haskell Tutorial(14)減輕型態負擔的型態參數〉的答案
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