Haskell:为什么不允许中缀类型构造函数?

标签 haskell types constructor infix-operator

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/

相关文章:

haskell - 无法将预期类型 ‘r’ 与实际类型 ‘Horse’ 匹配

haskell - getLine 和 readLn 之间的区别

Haskell ghci 使用 * 和 max 读取行为

angular - 为什么 Angular 不遵守方法签名中明确要求的 Date 类型?

java - 在基类构造函数中调用虚方法

java - Java中Instant类的构造函数?

haskell - Cabal 在需要分析库时不安装依赖项?

javascript - V8 是否检测 int 变量并更有效地处理它们?

java - 是先创建一个对象然后执行它的构造函数吗?

haskell - 大列表上的单体折叠中的堆栈溢出