Skip to content

Instantly share code, notes, and snippets.

@dskecse
Created August 16, 2014 23:08
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 dskecse/3449a3498a4b11c63193 to your computer and use it in GitHub Desktop.
Save dskecse/3449a3498a4b11c63193 to your computer and use it in GitHub Desktop.
Implementations of a function that converts a String to an Action
convertStringToAction :: String -> Action
convertStringToAction str = case str of
"Look" -> Look
"New" -> New
otherwise -> Quit
-- guards (охранные выражения)
convertStringToAction' :: String -> Action
convertStringToAction' str | str == "Look" = Look
| str == "New" = New
| otherwise = Quit
-- pattern matching (сопоставление с образцом)
convertStringToAction'' :: String -> Action
convertStringToAction'' "Look" = Look
convertStringToAction'' "New" = New
convertStringToAction'' _ = Quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment