Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created February 18, 2015 12:38
Show Gist options
  • Select an option

  • Save shigemk2/d70147b16bfdb7b00cee to your computer and use it in GitHub Desktop.

Select an option

Save shigemk2/d70147b16bfdb7b00cee to your computer and use it in GitHub Desktop.
import Data.Char
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")
]
string2digits :: String -> [Int]
string2digits = map digitToInt . filter isDigit
main = do
print $ Map.lookup "grace" phoneBook -- 該当しない場合はNothing
let newBook = Map.insert "grace" "341-9021" phoneBook
print $ Map.lookup "grace" newBook
print $ Map.size phoneBook
print $ Map.size newBook
print $ string2digits "948-9282"
let intBook = Map.map string2digits phoneBook
print $ Map.lookup "betty" intBook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment