[Haskell-cafe] :, infix operator, infix constructor, et cetera

Daniel C. Bastos dbast0s at yahoo.com.br
Sat Aug 25 19:33:56 EDT 2007

There is something called infix constructors and something else called
infix operators. I'm guessing that an infix operator is really a
function, and an infix constructor I don't know what it is. How would
you guys describe them?

(*) More questions.

I learned how to define (++), and then I wanted to see how (:) would be
defined. The Haskell 98 Report mentions that

-- The (:) operator is built-in syntax, and cannot legally be given
-- a fixity declaration; but its fixity is given by:
--   infixr 5  :

What does ``built-in syntax'' mean? 

Paul Hudak, in ``The Haskell School of Expression'' mentions that he
defines (:) legally, in Appendix A. After writing 

data [a] = [] | a : [a]  -- more pseudo-code
infixr 5 :

and making a couple of observations about it, he writes:

``The way (:) is defined here is actually legal syntax. Infix
constructors are permitted in *data* declarations, and are distinguished
from infix operators (for pattern-matching purposes) by the fact that
they must begin with a colon (a property trivially satisfied by ":").''

So I'm not sure what ``legal syntax'' and ``pseudo-code'' exactly
mean. The program

> module Main where 

> data [a] = [] | a : [a]
> infixr 5 :

> main = putStrLn "hello world"


%runhugs.exe Colon.lhs 
runhugs: Error occurred
ERROR "Colon.lhs":3 - Syntax error in data declaration (unexpected `[')

(*) The 5.

What does that 5 do in ``infixr 5 :''?

More information about the Haskell-Cafe mailing list