lambda表达式中分号的含义

Sta*_*nko 3 syntax lambda haskell

类型:

data Command a = Command String (a -> IO a) 
Run Code Online (Sandbox Code Playgroud)

功能:

iofunc_ :: String -> (a -> IO ()) -> Command a
iofunc_ s f = Command s (\x -> do f x ; return x)
Run Code Online (Sandbox Code Playgroud)

分号在lambda表达式中做了(\x -> do f x ; return x)什么?

Sib*_*ibi 8

他们只是将两个表达式分开f xreturn 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)
Run Code Online (Sandbox Code Playgroud)