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)
怎麼辦?
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)看到它。
它是「do」符號的一部分,而不是lambda。 – augustss