4 ms·
It's some time since I last worked in Haskell (and I never worked on anything useful), but I would write the function this way: getSocketAPIPort :: Int -> IO
by nemetroid 7y ago
It's some time since I last worked in Haskell (and I never worked on anything useful), but I would write the function this way:
getSocketAPIPort :: Int -> IO Int
getSocketAPIPort defaultPort = do
maybeEnvPort <- lookupEnv "socketPort"
return $ case maybeEnvPort of
Nothing -> defaultPort
Just port -> fromMaybe defaultPort (readMaybe port)
- zeendo 7y ago100% this is how I'd write it (except probably with pure instead of return). I don't get the desire to sprinkle bind throughout the other replies in this thread. I feel like it makes things less clear.