Created
January 28, 2020 02:09
-
-
Save johnlonganecker/6101d17d1396b734d9334b6836df5c80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- taken from https://www.youtube.com/watch?v=fg24wrRKE8g | |
import Prelude hiding (Maybe(..), lookup) | |
data Maybe a = Just a | Nothing | |
deriving Show | |
favoriteFoods :: [(String, String)] | |
favoriteFoods = [("David", "Green Papaya Salad") | |
,("Becky", "Sorbet")] | |
lookup key [] = Nothing | |
lookup key ((k, v) : rest) = if key == k then Just v else lookup key rest | |
fromMaybe def (Just a) = a | |
fromMaybe def Nothing = def | |
main = do | |
let favorite = lookup "Johan" favoriteFoods | |
print (fromMaybe "Ice Cream" favorite) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment