[GHC] #5168: Inaccessible branches not detected
GHC
cvs-ghc at haskell.org
Wed May 4 14:21:08 CEST 2011
#5168: Inaccessible branches not detected
---------------------------------+------------------------------------------
Reporter: simonpj | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.0.3
Keywords: | Testcase:
Blockedby: | Difficulty:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: None/Unknown
---------------------------------+------------------------------------------
C Rodrigues (red5_2 at hotmail.com) says: I was experimenting with using
GADTs for subtyping when I found something interesting. Hopefully someone
can satisfy my curiosity.
Here are two equivalent GADTs. My understanding was that GHC would
translate `Foo` and `Bar` into isomorphic data types. However, GHC 6.12.3
generates better code for `fooName` than for `barName`. In `fooName`,
there is no pattern match against `FooExtra`. In `barName`, there is a
pattern match against `BarExtra`. What makes these data types different?
{{{
data Tag
data TagExtra
--------
data Foo a where
Foo :: String -> Foo a
FooExtra :: IORef String -> Foo TagExtra
-- The cmm code for fooName does not match against 'FooExtra'
fooName :: Foo Tag -> String
fooName (Foo s) = s
--------
data Bar a where
Bar :: String -> Bar a
BarExtra :: a ~ TagExtra => IORef String -> Bar a
-- The cmm code for barName will try to pattern-match against 'BarExtra'
barName :: Bar Tag -> String
barName (Bar s) = s
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5168>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list