Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created February 18, 2015 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shigemk2/05013b524c2dc516e6ad to your computer and use it in GitHub Desktop.
Save shigemk2/05013b524c2dc516e6ad to your computer and use it in GitHub Desktop.
import qualified Data.Map as Map
phoneBook :: Map.Map String String
phoneBook = Map.fromList $
[("betty", "555-2938")
,("bonnie", "452-2928")
,("patsy", "493-2928")
,("lucille", "205-2928")
,("wendy", "939-8282")
,("penny", "853-2492")
]
main = do
-- lookup :: Eq a => a -> [(a, b)] -> Maybe b
-- Map(連想リスト)からキーを検索して、ValueとしてMaybeを返している
print $ Map.lookup "betty" phoneBook -- Just "555-2938"
print $ Map.lookup "wendy" phoneBook -- Just "939-8282"
print $ Map.lookup "grace" phoneBook -- 該当しない場合はNothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment