<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
I was experimenting with using GADTs for subtyping when I found something interesting. Hopefully someone can satisfy my curiosity.<div><br></div><div>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?<div><br></div><div><br></div><div><div>data Tag</div><div>data TagExtra</div><div><br></div><div>--------</div><div><br></div><div>data Foo a where</div><div> Foo :: String -> Foo a</div><div> FooExtra :: IORef String -> Foo TagExtra</div><div><br></div><div>-- The cmm code for fooName does not match against 'FooExtra'</div><div>fooName :: Foo Tag -> String</div><div>fooName (Foo s) = s</div><div><br></div><div>--------</div><div><br></div><div>data Bar a where</div><div> Bar :: String -> Bar a</div><div> BarExtra :: a ~ TagExtra => IORef String -> Bar a</div><div><br></div><div>-- The cmm code for barName will try to pattern-match against 'BarExtra'</div><div>barName :: Bar Tag -> String</div><div>barName (Bar s) = s</div></div><div><br></div></div>                                            </body>
</html>