[GHC] #13290: Data constructors should not have RULES
GHC
ghc-devs at haskell.org
Fri Feb 17 15:22:00 UTC 2017
#13290: Data constructors should not have RULES
-------------------------------------+-------------------------------------
Reporter: simonpj | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
Keywords: | Operating System: Unknown/Multiple
Architecture: | Type of failure: None/Unknown
Unknown/Multiple |
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
GHC has never (knowingly) supported rules for data constructors, like
{{{
{-# RULES
"BadBadBad" Just [x,y] = Just []
#-}
Notice that the rule is for the ''constructor itself''. Presumably the
intent is that any occurrence of `Just` appplied to a two-element list
will rewrite to `Just []`.
But currently they are accidentally allowed through, and then behave in
mysterious ways because of constructor wrappers. Duncan Coutts says
{{{
> Well I've certainly tried to use that in the past.
> A previous version of the cbor lib which used a different
> representation did a lot of matching on constructors to re-arrange
> input to an interpreter, until I discovered that GHC actually uses
> constructor wrappers and that matching on constructors was thus not
> reliable
}}}
I think we should simply make it illegal for now. If you really want it,
use a smart constructor thus
{{{
mkJust x = Just x
{-# INLINE [0] mkJust #-}
{-# RULES “Good” mkJust [x,y] = mkJust [] #-}
}}}
So let us
* Check in that you don't try to write a rule for a data constructor.
* Document in the user manual
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13290>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list