Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created Apr 1, 2015
Embed
What would you like to do?
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