':..'在Haskell中意味着什么?

Ale*_*lov 19 constructor haskell infix-notation

我正在阅读以下数据类型:

data Ne
  = NVar Id
  | Ne :.. (Clos Term)
  | NSplit Ne (Bind (Bind (Clos Term)))
  | NCase Ne (Clos [(Label, Term)])
  | NForce Ne
  | NUnfold Ne (Bind (Clos Term))
  deriving (Show, Eq)
Run Code Online (Sandbox Code Playgroud)

什么是:..在第二个成员声明中?

sep*_*p2k 20

构造函数的名称可以是以大写字母开头的字母数字,也可以是以冒号开头的符号.在后一种情况下,操作符将像中缀函数一样使用中缀.

所以:..Ne类型的中缀构造函数,它接受类型Ne(左操作数)和类型Clos Term(右操作数)之一的参数.


Fre*_*Foo 12

:..是代数数据类型的构造函数之一Ne.由标点符号和起点组成的构造函数名称:将成为中缀运算符.试试这个:

module Main where

data List a = Nil
            | a :.. (List a)
            deriving Show

main = print (1 :.. (2 :.. Nil))
Run Code Online (Sandbox Code Playgroud)