Opened 12 years ago

Closed 12 years ago

Last modified 9 years ago

#1497 closed bug (invalid)

Rebinding (:) -- built-in syntax, or just another constructor?

Reported by: dons Owned by:
Priority: low Milestone:
Component: Compiler (Parser) Version: 6.6
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


This program is valid in Hugs 2005, but not in GHC:

import Prelude (print,(<),Bool(..))

data Cond a = a : a

infixl 0 ?
infixl 1 :

(?) :: Bool -> Cond a -> a
True  ? (x : _) = x
False ? (_ : y) = y

main = print (1 < 2 ? "yeah" : "no!")

Hugs responds with:

Main> main

GHCi says:

$ ghci A.hs
A.hs:4:16: Illegal binding of built-in syntax: :

Which one is right?

Change History (4)

comment:1 Changed 12 years ago by simonmar

Resolution: invalid
Status: newclosed

GHC is right here, I think. It's disallowed by the Haskell 98 syntax: a data declaration can define a consym, which excludes all reservedop, and : is one of the reservedops.

Of course it's convenient for the compiler to allow you to define :, because then the Prelude can define the built-in list type, which is probably why Hugs allows this. GHC also does this, but adds extra checks to disallow defining : outisde of the standard libraries, as per Haskell 98.

comment:2 Changed 10 years ago by simonmar

Architecture: MultipleUnknown/Multiple

comment:3 Changed 10 years ago by simonmar

Operating System: UnknownUnknown/Multiple

comment:4 Changed 9 years ago by simonmar

difficulty: Easy (1 hr)Easy (less than 1 hour)
Note: See TracTickets for help on using tickets.