类型:
data Command a = Command String (a -> IO a)
功能:
iofunc_ :: String -> (a -> IO ()) -> Command a
iofunc_ s f = Command s (\x -> do f x ; return x)
分号在lambda表达式(\x -> do f x ; return x)
中做了什么?
他们只用表示法将两个表达式f x
和return x
分开。事实上,这些都与您的情况相同:
iofunc_ s f = Command s (\x -> do f x ; return x)
iofunc_ s f = Command s (\x -> do {f x ; return x})
iofunc_ s f = Command s (\x -> do f x
return x)
iofunc_ s f = Command s (\x -> f x >> return x)
任何地方的分号等同于线的更改缩进到与前一个有效表达式相同的级别。
我通过查看缩进的工作方式(https://en.wikibooks.org/wiki/Haskell/Indentation)看到了它。