lambda表达式中分号的含义

问题描述 投票:3回答:2

类型:

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)中做了什么?

haskell lambda syntax
2个回答
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)

1
投票

任何地方的分号等同于线的更改缩进到与前一个有效表达式相同的级别。

我通过查看缩进的工作方式(https://en.wikibooks.org/wiki/Haskell/Indentation)看到了它。

© www.soinside.com 2019 - 2024. All rights reserved.