DEV Community

Discussion on: Daily Challenge #56 - Coffee Shop

Collapse
 
craigmc08 profile image
Craig McIlwrath • Edited

Haskell

import qualified Data.Map.Strict as M

coffees = M.fromList [ (2.2, "Americano")
                     , (2.3, "Latte") 
                     , (2.4, "Flat white") 
                     , (3.5, "Filter")
                     ]

coffee :: Double -> String
coffee price = let maybeName = M.lookup price coffees
               in case maybeName of
                 Nothing -> "Sorry, exact change only. Try again tomorrow!" 
                 Just name -> "Here is your " ++ name ++ ", have a nice day!"