Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created April 1, 2015 11:59
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/19e7d35662b7cbbe5a87 to your computer and use it in GitHub Desktop.
Save shigemk2/19e7d35662b7cbbe5a87 to your computer and use it in GitHub Desktop.
data TrafficLight = Red | Yellow | Green
instance Eq TrafficLight where
Red == Red = True
Green == Green = True
Yellow == Yellow = True
_ == _ = False
instance Show TrafficLight where
show Red = "Red light"
show Yellow = "Yellow light"
show Green = "Green light"
main = do
print $ Red == Red
print $ Red == Yellow
print $ Red `elem` [Red, Yellow, Green]
print $ [Red, Yellow, Green]
-- True
-- False
-- True
-- [Red light,Yellow light,Green light]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment