Swift 中的 'const' 关键字是什么?
What is the 'const' keyword in Swift?
我正在阅读 this 文章,我遇到了以下两个函数:
// Sequence actions, discarding the value of the second argument
func <* <A, B>(p: Parser<A>, q: Parser<B>) -> Parser<A> {
return const <^> p <*> q
}
// Sequence actions, discarding the value of the first argument
func *> <A, B>(p: Parser<A>, q: Parser<B>) -> Parser<B> {
return const(id) <^> p <*> q
}
const
和 const(id)
是什么?我猜他们是某种价值观,但什么价值观?它们是隐式的左侧操作数还是右侧操作数? (这只是在黑暗中拍摄)。我找不到任何相关信息。
Swift 没有 const
关键字。
演讲使用the TryParsec library, which defines this const
function:
/// Constant function.
internal func const<A, B>(_ a: A) -> (B) -> A
{
return { _ in a }
}
我正在阅读 this 文章,我遇到了以下两个函数:
// Sequence actions, discarding the value of the second argument
func <* <A, B>(p: Parser<A>, q: Parser<B>) -> Parser<A> {
return const <^> p <*> q
}
// Sequence actions, discarding the value of the first argument
func *> <A, B>(p: Parser<A>, q: Parser<B>) -> Parser<B> {
return const(id) <^> p <*> q
}
const
和 const(id)
是什么?我猜他们是某种价值观,但什么价值观?它们是隐式的左侧操作数还是右侧操作数? (这只是在黑暗中拍摄)。我找不到任何相关信息。
Swift 没有 const
关键字。
演讲使用the TryParsec library, which defines this const
function:
/// Constant function.
internal func const<A, B>(_ a: A) -> (B) -> A
{
return { _ in a }
}