Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Gumballs!
data Action = Coin | Turn deriving Show
data Locked = Locked | Unlocked deriving Show
data State = State { locked :: Locked, coins :: Int, gumballs :: Int } deriving Show
update :: Action -> State -> State
update Coin s@(State { locked = Locked, gumballs = g }) | g == 0 = s
update Coin s@(State { locked = Locked, coins = c }) = s { locked = Unlocked, coins = c + 1 }
update Turn s@(State { locked = Unlocked, gumballs = g }) = s { locked = Locked, gumballs = g - 1 }
update _ s = s
main = putStrLn $ show $ update Turn $ update Coin State { locked = Locked, coins = 0, gumballs = 100 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment