<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. &nbsp;Hopefully someone can satisfy my curiosity.<div><br></div><div>Here are two equivalent GADTs. &nbsp;My understanding was that GHC would translate "Foo" and "Bar" into isomorphic data types. &nbsp;However, GHC 6.12.3 generates better code for 'fooName' than for 'barName'. &nbsp;In 'fooName', there is no pattern match against 'FooExtra'. &nbsp;In 'barName', there is a pattern match against 'BarExtra'. &nbsp;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>&nbsp;&nbsp;Foo :: String -&gt; Foo a</div><div>&nbsp;&nbsp;FooExtra :: IORef String -&gt; Foo TagExtra</div><div><br></div><div>-- The cmm code for fooName does not match against 'FooExtra'</div><div>fooName :: Foo Tag -&gt; String</div><div>fooName (Foo s) = s</div><div><br></div><div>--------</div><div><br></div><div>data Bar a where</div><div>&nbsp;&nbsp;Bar :: String -&gt; Bar a</div><div>&nbsp;&nbsp;BarExtra :: a ~ TagExtra =&gt; IORef String -&gt; Bar a</div><div><br></div><div>-- The cmm code for barName will try to pattern-match against 'BarExtra'</div><div>barName :: Bar Tag -&gt; String</div><div>barName (Bar s) = s</div></div><div><br></div></div>                                               </body>
</html>