Skip to content

Instantly share code, notes, and snippets.

@gouf
Created April 5, 2014 12:39
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 gouf/9991455 to your computer and use it in GitHub Desktop.
Save gouf/9991455 to your computer and use it in GitHub Desktop.
Haskell 練習
madam = "Madam, I'm Adam."
remove chr str = [c | c <- str, c /= chr]
removeCommas str = remove ',' str
removeBlanks str = remove ' ' str
removePeriods str = remove '.' str
{--
removeCommas str = [c | c <- str, c /= ',']
removeBlanks str = [c | c <- str, c /= ' ']
removePeriods str = [c | c <- str, c /= '.']
--}
removeBPC str = ((removeCommas.removeBlanks.removePeriods) str)
removeAd str = (remove 'A'. remove 'd') str
main = do
print $ madam
print (removeCommas(madam))
print (removeBPC madam)
print $ remove '\'' madam
print $ removeAd madam
--- Output
{--
"Madam, I'm Adam."
"Madam I'm Adam."
"MadamI'mAdam"
"Madam, Im Adam."
"Maam, I'm am."
--}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment