Though I should add that it's in general against the Haskell spirit to write code against needlessly specific types and to combine unrelated functionality. So, I'd first look for a function or write one myself in some…
here's ho I'd write it: getSocketAPIPort :: Int -> IO Int getSocketAPIPort defaultPort = readWithDefault <$> lookupEnv "socketPort" where readWithDefault mbPort = fromMaybe defaultPort $ readMaybe =<< mbPort
Though I should add that it's in general against the Haskell spirit to write code against needlessly specific types and to combine unrelated functionality. So, I'd first look for a function or write one myself in some…
here's ho I'd write it: getSocketAPIPort :: Int -> IO Int getSocketAPIPort defaultPort = readWithDefault <$> lookupEnv "socketPort" where readWithDefault mbPort = fromMaybe defaultPort $ readMaybe =<< mbPort