DEV Community

loading...

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!" 
Collapse
citizen428 profile image
Michael Kohl • Edited

Am I missing something or is the import of isJust a leftover from a previous version, i.e. did you have an if instead of the match expression before?

Collapse
craigmc08 profile image
Craig McIlwrath

You are correct. I edited my original comment.