在 Haskell 98 report , 我找到了这个:
The syntax for Haskell type expressions is given above. Just as data values are built using data constructors, type values are built from type constructors. As with data constructors, the names of type constructors start with uppercase letters. Unlike data constructors, infix type constructors are not allowed (other than (->)).
没有给出为什么不允许中缀类型构造函数的原因。在 Agda 等中,中缀类型构造函数是司空见惯的。为什么不在 Haskell 中?
最佳答案
它不是 Haskell 标准的一部分,而是作为 jamshidh提到它在 GHC 中仍然是可能的。需要注意的是数据构造函数(不是类型构造函数)必须以冒号开头:
{-# LANGUAGE TypeOperators #-}
data a + b = a :+ b
f :: a + b -> a
f (a :+ b) = a
g :: a + b -> b
g (a :+ b) = b
关于Haskell:为什么不允许中缀类型构造函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30039123/