News for hackers. Stuff that matters.
Re:Show HN: I built a poker site with Haskell by nemetroid on Friday August 09, 2019 @01:18PM (#20656376)
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)
Re:Show HN: I built a poker site with Haskell by zeendo on Friday August 09, 2019 @03:33PM (#20657600)
100% 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.