类型:
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)
中起什么作用?
最佳答案
它们只是用 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 -> do f x
return x)
iofunc_ s f = Command s (\x -> f x >> return x)
关于haskell - lambda 表达式中分号的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27646966/