“varid”,“varsym”和“varid”之间的语义差异是什么?在Haskell报告中? [英] What is the semantic difference between "varid", "varsym" in Haskell Report?
问题描述
我正在阅读2010年的Haskell报告,并且有关于2.4节中的元逻辑表示的一些问题这里:
- 在varid和varsym的助记符中,var是指变量吗?
- 我的理解是,varid是变量和函数的标识符,而varsym也是标识符,但是对于运算符。这种理解是否正确?
- 如果1和2是正确的,是否意味着operator也是一种变量? (我很困惑,因为这可能是不对的。)
欣赏任何建议。解决方案
据我所知,报告定义了使用前缀的符号和使用中缀的符号之间的区别,例如:
b$ b
fxy - f用于前缀
a / b - /用于中缀
$ b这只是一个句法上的便利,因为所有的前缀符号都可以用反斜杠加中缀,而且所有的中缀符号都可以用前缀
()
s:x`f` y - 中缀
(/)ab - 前缀
(a /)b - 运算符部分
(/ b)a - 运算符部分
小问题:
- )
无法找出
id
和sym
部分的任何有意义的助记符。 :(
- 是的,我会同意运算符是变量,但绑定到符号符号的值不会是变量。
运算符处于Haskell语法领域,而不是其语义,它们仅用于为编写某些表达式提供更方便的语法。就我所知,如果它们从Haskell中被移除,唯一的损失将是方便的语法 - 也就是说,除了方便的语法之外,没有什么需要运算符的,并且可以用非运算符符号替换运算符的每一次使用。它们与变量完全相同 - 它们是变量 - 但需要不同的语法来使用它们。
I am reading the Haskell report 2010 and has some questions with regarding to the meta-logical representation in section 2.4Here:
- In the mnemonics of "varid" and "varsym", does "var" mean variable?
- My understanding are that "varid" are identifiers for variables and functions, while "varsym" are identifiers also, but for operators. Is this understanding correct?
- If 1 and 2 are correct, does it mean operator is also a kind of variable? (I am very confused because this is likely not right.)
Appreciate any advice.
解决方案As far as I can tell, the report is defining the difference between symbols that are used prefix, and those that are used infix, for example:
f x y -- f is used prefix a / b -- / is used infix
This is just a syntactic convenience, as all prefix symbols can be used infix with backticks, and all infix symbols can be used prefix with
()
s:x `f` y -- infix (/) a b -- prefix (a /) b -- operator section (/ b) a -- operator section
Sub-questions:
yes, but I can't figure out any meaningful mnemonic for the
id
andsym
parts. :(operators are in the realm of Haskell syntax, not its semantics. They're only used to provide a more convenient syntax for writing some expressions. As far as I know, if they were removed from Haskell, the only loss would be convenient syntax -- i.e. there's nothing that you need operators for, other than convenient syntax, and you can replace every single use of operators with non-operator symbols. They are completely identical to variables -- they are variables -- but require different syntax for their use.
yes, I would agree that operator symbols are variables. However, the values bound to oerators symbols would not be variables.
这篇关于“varid”,“varsym”和“varid”之间的语义差异是什么?在Haskell报告中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!