标签: haskell monads
我觉得我应该已经知道这一点了,但是如何在一行中使用fromMaybe而不是使用let将其分为2?
fromMaybe
let
main = do maybePort <- lookupEnv "PORT" let port = fromMaybe "4020" maybePort putStrLn $ "Listening on:" ++ port
答案 0 :(得分:8)
您可以像这样使用fmap或<$>:
fmap
<$>
import Control.Applicative ((<$>)) main = do port <- fromMaybe "4020" <$> lookupEnv "PORT" putStrLn $ "Listening on:" ++ port