I notice that the these two definitions are no where to be found in the most official resource of Haskell documentation:
(:) :: a -> [a] -> [a]
data [] a = [] | a : []
I checked Hoogle and there are no entries for data [] or (:). Are these two not supposed to be "normal" function and data type?
Edit: In the Haskell 2010 Language Report, they say that
-- The (:) operator is built-in syntax, and cannot legally be given
-- a fixity declaration; but its fixity is given by:
-- infixr 5 :
But why? Is there a particular reason for this function to be singled out?
It's built-in syntax, not really a built-in function. The function (:) is just one of the two constructors of the built-in type []. However:
[], is not valid Haskell syntax for a type-name; so it must be built-in syntax.[a] for an instantiation of [] is built-in syntax.[], is not valid Haskell syntax for a constructor name; so it must be built-in syntax.[ x, y, z ] is built-in syntax (obviously).Since essentially everything else about the type [] is built-in syntax, the decision was made to make : built-in syntax as well, rather than having it be the one exception that actually was a valid name in the language.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With