module Haskell3 where import qualified Data.Map as M import Control.Monad -- define Monads yeahhhh foo :: Maybe String foo = do x <- Just 3 y <- Just "!" Just (show x ++ y) -- Carrier example with maps and monads double yeahhh type PersonName = String type PhoneNumber = String type BillingAddress = String data MobileCarrier = TIM | Vodadone | Wind deriving (Eq, Ord, Show) findCarrierBillingAddress :: PersonName -> M.Map PersonName Phonenumber -> M.Map PhoneNumber MobileCarrier -> M.Map MobileCarrier BillingAddress -> Maybe BillingAddress findCarrierBillingAddress person phoneMap carrierMap addressMap = case M.lookup person phoneMap of Nothing -> Nothing Just number -> case M.lookup number carrierMap of Nothing -> Nothing Just carrier -> M.lookup carrier addresMap findCarrierBillingAddress2 :: PersonName -> M.Map PersonName Phonenumber -> M.Map PhoneNumber MobileCarrier -> M.Map MobileCarrier BillingAddress -> Maybe BillingAddress findCarrierBillingAddress2 person phoneMap carrierMap addressMap = do number <- M.lookup person phoneMap carrier <- M.lookup number carrierMap M.lookup carrier addressMap