<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin-top:6.0pt;
        margin-right:0cm;
        margin-bottom:6.0pt;
        margin-left:0cm;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:6.0pt;
        margin-right:0cm;
        margin-bottom:6.0pt;
        margin-left:36.0pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
p.Code, li.Code, div.Code
        {mso-style-name:Code;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Courier New";
        mso-fareast-language:EN-US;}
span.EmailStyle18
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
.MsoPapDefault
        {mso-style-type:export-only;
        margin-top:6.0pt;
        margin-right:0cm;
        margin-bottom:6.0pt;
        margin-left:0cm;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1664969688;
        mso-list-type:hybrid;
        mso-list-template-ids:749631586 134807553 134807555 134807557 134807553 134807555 134807557 134807553 134807555 134807557;}
@list l0:level1
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l0:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level3
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l0:level4
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l0:level5
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level6
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l0:level7
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l0:level8
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level9
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:12.0pt">Friends<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">I want to make withdraw (or, rather, simplify) a little-known feature in GHC, but before I do so I want to check that no one is going to have a heart attack.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">Relevant bits of the user manual:
<a href="http://www.haskell.org/ghc/docs/latest/html/users_guide/type-families.html#assoc-decl">
http://www.haskell.org/ghc/docs/latest/html/users_guide/type-families.html#assoc-decl</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">All of this arose when thinking about fixing Trac #9063.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">I believe that this change will affect essentially nobody, and I propose to implement forthwith in HEAD (and hence 7.10). 
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">Does anyone object?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">Thanks<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">Simon<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:16.0pt">The issue<o:p></o:p></span></b></p>
<p class="MsoNormal"><span style="font-size:12.0pt">Consider this:<o:p></o:p></span></p>
<p class="Code">class C a where<o:p></o:p></p>
<p class="Code">   type T a b :: *<o:p></o:p></p>
<p class="Code"><o:p> </o:p></p>
<p class="Code">instance C [x] where<o:p></o:p></p>
<p class="Code">   type T [x] b = x -> b<o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:12.0pt">That is just what you’d expect.  But currently this is allowed too:<o:p></o:p></span></p>
<p class="Code">instance C [x] where<o:p></o:p></p>
<p class="Code">   type T [x] Int = x -> Int<o:p></o:p></p>
<p class="Code">   type T [x] Bool = Bool -> x<o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:12.0pt">That is, <b>GHC 7.8 allows many associated type instances</b>, provided they don’t overlap.  But, oddly you can’t further instantiate the instance pattern. This would make just as much sense, but isn’t allowed:<o:p></o:p></span></p>
<p class="Code">instance C [x] where<o:p></o:p></p>
<p class="Code">   type T [Int] b = b -> Int<o:p></o:p></p>
<p class="Code">   type T [Bool] b = Bool -> b<o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:12.0pt">Moreover, as the user manual says, for an open kind like *, none of this really makes sense. It really only makes sense for a closed kind. Something like<o:p></o:p></span></p>
<p class="Code">class D a where<o:p></o:p></p>
<p class="Code">   type S (b :: Bool) a :: *<o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:12.0pt">Now <i>this</i> would make some kind of sense:<o:p></o:p></span></p>
<p class="Code">instance D [x] where<o:p></o:p></p>
<p class="Code">   type S True [x] = x -> x<o:p></o:p></p>
<p class="Code">   type S False [x] = x<o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:12.0pt">But for closed kinds, you really want a
<i>closed</i> type family.  So this would be better:<o:p></o:p></span></p>
<p class="Code">instance D [x] where<o:p></o:p></p>
<p class="Code">   type S b [x] = SHelp x b<o:p></o:p></p>
<p class="Code"><o:p> </o:p></p>
<p class="Code">type family SHelp x b where<o:p></o:p></p>
<p class="Code">  SHelp x True = x -> x<o:p></o:p></p>
<p class="Code">  SHelp x False = x<o:p></o:p></p>
<p class="Code"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-size:12.0pt">So yes, you do have to declare a named helper type, but you get something much more perspicuous and explicit in exchange.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">All of this also applies to the default declaration(s) which you can supply for an associated type (see 7.7.3.2 in the link above), only it’s a bit more complicated and indirect.<o:p></o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:16.0pt">My solution<o:p></o:p></span></b></p>
<p class="MsoNormal"><span style="font-size:12.0pt">I propose to simplify substantially, as follows:<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><![if !supportLists]><span style="font-size:12.0pt;font-family:Symbol"><span style="mso-list:Ignore">·<span style="font:7.0pt "Times New Roman"">        
</span></span></span><![endif]><span style="font-size:12.0pt">The “shared arguments” of an associated type are the argument positions that mention a type variable from the class header.  So in class C above, the first argument position of T is “shared”; and
 in class D, the second argument position of S is shared.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><![if !supportLists]><span style="font-size:12.0pt;font-family:Symbol"><span style="mso-list:Ignore">·<span style="font:7.0pt "Times New Roman"">        
</span></span></span><![endif]><span style="font-size:12.0pt">A instance for an associated type (in a class instance declaration) cf 7.7.3.1 must have
<o:p></o:p></span></p>
<p class="MsoListParagraph" style="margin-left:72.0pt;text-indent:-18.0pt;mso-list:l0 level2 lfo1">
<![if !supportLists]><span style="font-size:12.0pt;font-family:"Courier New""><span style="mso-list:Ignore">o<span style="font:7.0pt "Times New Roman"">  
</span></span></span><![endif]><span style="font-size:12.0pt">type variables in the non-shared argument positions, and
<o:p></o:p></span></p>
<p class="MsoListParagraph" style="margin-left:72.0pt;text-indent:-18.0pt;mso-list:l0 level2 lfo1">
<![if !supportLists]><span style="font-size:12.0pt;font-family:"Courier New""><span style="mso-list:Ignore">o<span style="font:7.0pt "Times New Roman"">  
</span></span></span><![endif]><span style="font-size:12.0pt">an exact copy of the corresponding instance header type in the shared positions<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><![if !supportLists]><span style="font-size:12.0pt;font-family:Symbol"><span style="mso-list:Ignore">·<span style="font:7.0pt "Times New Roman"">        
</span></span></span><![endif]><span style="font-size:12.0pt">For each associated type you can have
<o:p></o:p></span></p>
<p class="MsoListParagraph" style="margin-left:72.0pt;text-indent:-18.0pt;mso-list:l0 level2 lfo1">
<![if !supportLists]><span style="font-size:12.0pt;font-family:"Courier New""><span style="mso-list:Ignore">o<span style="font:7.0pt "Times New Roman"">  
</span></span></span><![endif]><span style="font-size:12.0pt">at most one default declaration in the class declaration<o:p></o:p></span></p>
<p class="MsoListParagraph" style="margin-left:72.0pt;text-indent:-18.0pt;mso-list:l0 level2 lfo1">
<![if !supportLists]><span style="font-size:12.0pt;font-family:"Courier New""><span style="mso-list:Ignore">o<span style="font:7.0pt "Times New Roman"">  
</span></span></span><![endif]><span style="font-size:12.0pt">at most one type instance declaration in the class instance declaration<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><o:p> </o:p></span></p>
</div>
</body>
</html>