以冒号开头的运算符符号是构造函数

An operator symbol starting with a colon is a constructor

我学Haskell。来自 Haskell 2010 文档:

  • An operator symbol starting with a colon is a constructor.
  • An operator symbol starting with any other character is an ordinary identifier.

我不明白第一个短语。我知道存在 数据构造函数 class 类型构造函数 。这个案例是什么构造函数?也许我需要一个代码示例。

你可以定义像

这样的东西
data Symbolic n
   = Constant n
   | Variable String
   | Symbolic n :+ Symbolic n
   | Symbolic n :* Symbolic n
  deriving (Show)

GHCi> let v = Variable; c = Constant
GHCi> c 2 :* v"a" :+ c 3
    (Constant 2 :* Variable "a") :+ Constant 3

这就是第一个短语所指的。

I know exist data constructors and class type constructors. What constructor this case?

在标准 Haskell 中,只有数据构造函数可以是符号的,类型名称必须是字母数字。如果启用 GHC 扩展 TypeOperators,类型名称也可以是符号名称,允许您定义以 :.

开头的类型构造函数