【发布时间】:2017-01-14 21:31:26
【问题描述】:
我还在学习 Haskell 和调试一些函数,并且通常有一个时间戳函数来了解某些操作何时开始和停止:
doSomeAction :: String -> IO ()
doSomeAction arg1 = do
putStrLn =<< makeTime
theThingthatTakesAwhile arg1
putStrLn =<< makeTime
where
makeTime = (formatTime defaultTimeLocale "%Y%m%d%H%M%S") <$> getZonedTime
我的=<< 和where 子句包含<$> 是与getZonedTime 周围的IO 交互的合理方式吗?
λ> :t getZonedTime
getZonedTime :: IO ZonedTime
或者这是对我或读者的误导还是非惯用语?
输出是:
20170114152312
Doing some long function....
20170114152336
这正是我想看到的——它告诉我我需要什么。对putStrLn =<< something 来说,获得这种效果似乎很奇怪。
【问题讨论】: