How to use type constructor in infix form

> :set -XTypeOperators
> data a :-> b = C (a -> b)
> :t C id
C id :: b :-> b

Remember that its name must start with : (roughly, : is considered "uppercase"). (No longer needed -- see the answer by Cactus for more information)

Otherwise, use backticks, as in a `T` b.


To expand on @chi's answer, with recent GHC versions, the syntax of TypeOperators has changed somewhat: type constructor names that would otherwise be infix type variable names (i.e. symbols without a leading :) are still classified as type constructor names, meaning the following code works and defines an infix type constructor +:

{-# language TypeOperators #-}

data a + b = L a | R b

Tags:

Syntax

Haskell