Ticket #1497 (closed bug: invalid)

Opened 6 years ago

Last modified 4 years ago

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: Difficulty: Easy (less than 1 hour)
Test Case: Blocked By:
Blocking: Related Tickets:

Description

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
"yeah"

GHCi says:

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

Which one is right?

Change History

Changed 6 years ago by simonmar

  • status changed from new to closed
  • resolution set to invalid

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.

Changed 5 years ago by simonmar

  • architecture changed from Multiple to Unknown/Multiple

Changed 5 years ago by simonmar

  • os changed from Unknown to Unknown/Multiple

Changed 4 years ago by simonmar

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