Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Bob (responseFor) where
  2. import Data.Char
  3.  
  4. responseForNothing = "Fine. Be that way!"
  5. responseForYelledQuestion = "Calm down, I know what I'm doing!"
  6. responseForShout = "Whoa, chill out!"
  7. responseForQuestion = "Sure."
  8. responseForAnythingElse = "Whatever."
  9.  
  10. isQuestion xs = last xs == '?'
  11.  
  12. responseForShouting :: String -> String
  13. responseForShouting xs
  14.   | isQuestion xs = responseForYelledQuestion
  15.   | otherwise = responseForShout
  16.  
  17. responseFor :: String -> String
  18. responseFor xs
  19.   | (null . filter isAlphaNum) xs = responseForNothing
  20.   | (all isUpper && null) (filter isAlpha xs) = responseForShouting xs
  21.   | isQuestion xs = responseForQuestion
  22.   | otherwise = responseForAnythingElse
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement