Skip to content

RULES don't apply to a newtype constructor

For some reason, RULES that involve a newtype constructor never seem to fire. The following program demonstrates the problem:

module Main where

newtype Foo a = Foo { unFoo :: a }
  deriving Show

foo :: a -> Foo a
foo = Foo

{-# RULES "rule Foo"  forall v.  Foo v = error "Foo" #-}
{-# RULES "rule foo"  forall v.  foo v = error "foo" #-}

main :: IO ()
main = do
    print (Foo ())
    print (foo ())

"rule foo" fires, but "rule Foo" doesn't. The program prints

Foo {unFoo = ()}
D: foo

Note that this doesn't seem to affect selectors, only constructors.

Trac metadata
Trac field Value
Version 7.6.1
Type Bug
TypeOfFailure IncorrectResultAtRuntime
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information