Search code examples
haskelltypesconstructorinfix-operator

Haskell: Why aren't infix type constructors allowed?


In the Haskell 98 report, I found this:

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 (->)).

No reasons as to why infix type constructors aren't allowed are given. In Agda and the like, infix type constructors are commonplace. Why not in Haskell?


Solution

  • It's not part of the Haskell standard, but as jamshidh mentions it is still possible in GHC. The caveat is that data constructors (not type constructors) must start with a colon:

    {-# LANGUAGE TypeOperators #-}
    
    data a + b = a :+ b
    
    f :: a + b -> a
    f (a :+ b) = a
    
    g :: a + b -> b
    g (a :+ b) = b