<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none"><!--P{margin-top:0;margin-bottom:0;} .ms-cui-menu {background-color:#ffffff;border:1px rgb(171, 171, 171) solid;font-family:'Segoe UI WPC', 'Segoe UI', Tahoma, 'Microsoft Sans Serif', Verdana, sans-serif;font-size:11pt;color:rgb(51, 51, 51);} .ms-cui-menusection-title {display:none;} .ms-cui-ctl {vertical-align:text-top;text-decoration:none;color:rgb(51, 51, 51);} .ms-cui-ctl-on {background-color:rgb(223, 237, 250);opacity: 0.8;} .ms-cui-img-cont-float {display:inline-block;margin-top:2px} .ms-cui-smenu-inner {padding-top:0px;} .ms-owa-paste-option-icon {margin: 2px 4px 0px 4px;vertical-align:sub;padding-bottom: 2px;display:inline-block;} .ms-rtePasteFlyout-option:hover {background-color:rgb(223, 237, 250) !important;opacity:1 !important;} .ms-rtePasteFlyout-option {padding:8px 4px 8px 4px;outline:none;} .ms-cui-menusection {float:left; width:85px;height:24px;overflow:hidden}.wf {speak:none; font-weight:normal; font-variant:normal; text-transform:none; -webkit-font-smoothing:antialiased; vertical-align:middle; display:inline-block;}.wf-family-owa {font-family:'o365Icons'}@font-face {  font-family:'o365IconsIE8';  src:url('prem/15.0.913.22/resources/styles/office365icons.ie8.eot?#iefix') format('embedded-opentype'),         url('prem/15.0.913.22/resources/styles/office365icons.ie8.woff') format('woff'),         url('prem/15.0.913.22/resources/styles/office365icons.ie8.ttf') format('truetype');  font-weight:normal;  font-style:normal;}@font-face {  font-family:'o365IconsMouse';  src:url('prem/15.0.913.22/resources/styles/office365icons.mouse.eot?#iefix') format('embedded-opentype'),         url('prem/15.0.913.22/resources/styles/office365icons.mouse.woff') format('woff'),         url('prem/15.0.913.22/resources/styles/office365icons.mouse.ttf') format('truetype');  font-weight:normal;  font-style:normal;}.wf-family-owa {font-family:'o365IconsMouse'}.ie8 .wf-family-owa {font-family:'o365IconsIE8'}.ie8 .wf-owa-play-large:before {content:'\e254';}.notIE8 .wf-owa-play-large:before {content:'\e054';}.ie8 .wf-owa-play-large {color:#FFFFFF/*$WFWhiteColor*/;}.notIE8 .wf-owa-play-large {border-color:#FFFFFF/*$WFWhiteColor*/; width:1.4em; height:1.4em; border-width:.1em; border-style:solid; border-radius:.8em; text-align:center; box-sizing:border-box; -moz-box-sizing:border-box; padding:0.1em; color:#FFFFFF/*$WFWhiteColor*/;}.ie8 .wf-size-play-large {width:40px; height:40px; font-size:30px}.notIE8 .wf-size-play-large {width:40px; height:40px; font-size:30px}
<!--
@font-face
        {font-family:"Cambria Math"}
@font-face
        {font-family:Calibri}
@font-face
        {font-family:"Segoe UI"}
@font-face
        {font-family:o365IconsIE8}
@font-face
        {font-family:o365IconsMouse}
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif"}
a:link, span.MsoHyperlink
        {color:#0563C1;
        text-decoration:underline}
a:visited, span.MsoHyperlinkFollowed
        {color:#954F72;
        text-decoration:underline}
p.Code, li.Code, div.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"}
p.code0, li.code0, div.code0
        {margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Courier New";
        color:#1F497D}
p.code00, li.code00, div.code00
        {margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Courier New";
        color:#1F497D}
p.ms-cui-menu, li.ms-cui-menu, div.ms-cui-menu
        {margin:0cm;
        margin-bottom:.0001pt;
        background:white;
        border:none;
        padding:0cm;
        font-size:11.0pt;
        font-family:"Segoe UI","sans-serif";
        color:#333333}
p.ms-cui-menusection-title, li.ms-cui-menusection-title, div.ms-cui-menusection-title
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif"}
p.ms-cui-ctl, li.ms-cui-ctl, div.ms-cui-ctl
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:#333333}
p.ms-cui-ctl-on, li.ms-cui-ctl-on, div.ms-cui-ctl-on
        {margin:0cm;
        margin-bottom:.0001pt;
        background:#DFEDFA;
        font-size:12.0pt;
        font-family:"Times New Roman","serif"}
p.ms-cui-img-cont-float, li.ms-cui-img-cont-float, div.ms-cui-img-cont-float
        {margin-top:1.5pt;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif"}
p.ms-cui-smenu-inner, li.ms-cui-smenu-inner, div.ms-cui-smenu-inner
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif"}
p.ms-owa-paste-option-icon, li.ms-owa-paste-option-icon, div.ms-owa-paste-option-icon
        {margin-top:1.5pt;
        margin-right:3.0pt;
        margin-bottom:0cm;
        margin-left:3.0pt;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        vertical-align:sub}
p.ms-rtepasteflyout-option, li.ms-rtepasteflyout-option, div.ms-rtepasteflyout-option
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif"}
p.ms-cui-menusection, li.ms-cui-menusection, div.ms-cui-menusection
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif"}
p.wf, li.wf, div.wf
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif"}
p.wf-family-owa, li.wf-family-owa, div.wf-family-owa
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:o365IconsMouse}
p.wf-owa-play-large, li.wf-owa-play-large, div.wf-owa-play-large
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif"}
p.wf-size-play-large, li.wf-size-play-large, div.wf-size-play-large
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif"}
p.wf-family-owa1, li.wf-family-owa1, div.wf-family-owa1
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:o365IconsIE8}
p.wf-owa-play-large1, li.wf-owa-play-large1, div.wf-owa-play-large1
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:white}
p.wf-owa-play-large2, li.wf-owa-play-large2, div.wf-owa-play-large2
        {margin:0cm;
        margin-bottom:.0001pt;
        text-align:center;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:white}
p.wf-size-play-large1, li.wf-size-play-large1, div.wf-size-play-large1
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:22.5pt;
        font-family:"Times New Roman","serif"}
p.wf-size-play-large2, li.wf-size-play-large2, div.wf-size-play-large2
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:22.5pt;
        font-family:"Times New Roman","serif"}
p.msochpdefault, li.msochpdefault, div.msochpdefault
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Times New Roman","serif"}
p.wf-family-owa2, li.wf-family-owa2, div.wf-family-owa2
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:o365IconsIE8}
p.wf-owa-play-large3, li.wf-owa-play-large3, div.wf-owa-play-large3
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:white}
p.wf-owa-play-large4, li.wf-owa-play-large4, div.wf-owa-play-large4
        {margin:0cm;
        margin-bottom:.0001pt;
        text-align:center;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:white}
p.wf-size-play-large3, li.wf-size-play-large3, div.wf-size-play-large3
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:22.5pt;
        font-family:"Times New Roman","serif"}
p.wf-size-play-large4, li.wf-size-play-large4, div.wf-size-play-large4
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:22.5pt;
        font-family:"Times New Roman","serif"}
span.codechar
        {font-family:"Courier New";
        color:#1F497D}
span.codechar0
        {font-family:"Courier New";
        color:#1F497D}
span.emailstyle38
        {font-family:"Calibri","sans-serif";
        color:#1F497D}
span.emailstyle47
        {font-family:"Calibri","sans-serif";
        color:#1F497D}
p.wf-family-owa3, li.wf-family-owa3, div.wf-family-owa3
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:o365IconsIE8}
p.wf-owa-play-large5, li.wf-owa-play-large5, div.wf-owa-play-large5
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:white}
p.wf-owa-play-large6, li.wf-owa-play-large6, div.wf-owa-play-large6
        {margin:0cm;
        margin-bottom:.0001pt;
        text-align:center;
        border:none;
        padding:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:white}
p.wf-size-play-large5, li.wf-size-play-large5, div.wf-size-play-large5
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:22.5pt;
        font-family:"Times New Roman","serif"}
p.wf-size-play-large6, li.wf-size-play-large6, div.wf-size-play-large6
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:22.5pt;
        font-family:"Times New Roman","serif"}
span.EmailStyle54
        {font-family:"Calibri","sans-serif";
        color:#1F497D}
.MsoChpDefault
        {font-size:10.0pt}
@page WordSection1
        {margin:72.0pt 72.0pt 72.0pt 72.0pt}
-->
--></style>
</head>
<body dir="ltr">
<div style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Methinks a lot of the former performance considerations in Unique are out-dated (as per earlier discussion; direct use of unboxed ints etc.).<br>
</p>
<p><br>
</p>
<p>An upside of using an ADT for the types of uniques is that we don't actually need to reserve 8 bits for a Char (which is committing to neither the actual number of classes, nor the "nature" of real Chars in Haskell). Instead, we can make a bitmask dependent
 on the number of classes that we actually use and stick the tag on the least-significant side of the Unique, as opposed to the most-significant (as we do now).</p>
<p><br>
</p>
<p>We want to keep things working on 32-bits, but maybe a future of parallel builds is only for 64-bits. In this case, I would suggest that the 64-bit-case looks like this:<br>
</p>
<p><br>
</p>
<p><thread_id_bits:8> <unique_id_bits:56-X> <tag_bits:X><br>
</p>
<p><br>
</p>
<p>whereas the 32-bit case simply has<br>
</p>
<p><br>
</p>
<p><unique_id_bits:32-X> <tag_bits:X></p>
<p><br>
</p>
<p>Where X is dependent on the size of the UniqueClass-sum-type (to be introduced). This would be CPP-magic'd using ​WORD_SIZE_IN_BITS.</p>
<p><br>
</p>
<p>Ph.</p>
<p><br>
</p>
<p><br>
<br>
</p>
<p><br>
</p>
<p><br>
</p>
<div style="color: rgb(40, 40, 40);">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Simon Peyton Jones <simonpj@microsoft.com><br>
<b>Sent:</b> 20 August 2014 13:01<br>
<b>To:</b> Holzenspies, P.K.F. (EWI); ghc-devs@haskell.org<br>
<b>Subject:</b> RE: Unique as special boxing type & hidden constructors</font>
<div> </div>
</div>
<div>
<div class="WordSection1">
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif"; color:#1F497D">Sounds like a good idea to me.   Would need to think about making sure that it all still worked, somehow, on 32 bit.</span></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif"; color:#1F497D">S</span></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<div style="border:none; border-left:solid blue 1.5pt; padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt; font-family:"Calibri","sans-serif"">From:</span></b><span lang="EN-US" style="font-size:11.0pt; font-family:"Calibri","sans-serif""> p.k.f.holzenspies@utwente.nl [mailto:p.k.f.holzenspies@utwente.nl]
<br>
<b>Sent:</b> 20 August 2014 11:31<br>
<b>To:</b> Simon Peyton Jones; ghc-devs@haskell.org<br>
<b>Subject:</b> RE: Unique as special boxing type & hidden constructors</span></p>
</div>
</div>
<p class="MsoNormal"> </p>
<div>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">Dear Simon, et al,</span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">I seem to recall that the Unique(Supply) was an issue in parallelising GHC itself. There's a comment in the code (signed JSM) that there aren't any 64-bit bugs, if we
 have at least 32-bits for Ints and Chars fit in 8 characters. Then, there's bitmasks like 0x00FFFFFF to separate the "Int-part" from the "Char-part".</span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">I was wondering; if we move Uniques to 64 bits, but use the top 16 (instead of the current 8) for *both* the tag (currently a Char, soon an sum-type) and the threadId
 of the supplying thread of a Unique, would that help?</span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">Regards,</span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">Philip</span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span></p>
<div>
<div class="MsoNormal" align="center" style="text-align:center; background:white">
<span style="font-family:"Calibri","sans-serif"; color:#282828">
<hr size="2" width="98%" align="center">
</span></div>
<div id="divRplyFwdMsg">
<p class="MsoNormal" style="background:white"><b><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:black">From:</span></b><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:black"> Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com">simonpj@microsoft.com</a>><br>
<b>Sent:</b> 18 August 2014 23:29<br>
<b>To:</b> Holzenspies, P.K.F. (EWI); <a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
<b>Subject:</b> RE: Unique as special boxing type & hidden constructors</span><span style="font-family:"Calibri","sans-serif"; color:#282828">
</span></p>
<div>
<p class="MsoNormal" style="background:white"><span style="font-family:"Calibri","sans-serif"; color:#282828"> </span></p>
</div>
</div>
<div>
<div>
<p style="margin-left:36.0pt; background:white"><span style="font-family:"Calibri","sans-serif"; color:black">1) There is a #ifdef define(__GLASGOW_HASKELL__), which confused me somewhat. Similar things occur elsewhere in the code. Isn't the assumption that
 GHC is being used? Is this old portability stuff that may be removed?</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span><span style="color:#282828"></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">I think so, unless others yell to the contrary.</span><span style="color:#282828"></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span><span style="color:#282828"></span></p>
<p style="margin-left:36.0pt; background:white"><span style="font-family:"Calibri","sans-serif"; color:black">2) Uniques are produced from a Char and an Int. The function to build Uniques (mkUnique) is not exported, according to the comments, so as to see all
 characters used. Access to these different "classes" of Uniques is given through specialised mkXXXUnique functions. Does anyone have a problem with something like:</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="margin-left:36.0pt; background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="margin-left:36.0pt; background:white"><span style="font-family:"Calibri","sans-serif"; color:black">> data UniqueClass</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="margin-left:36.0pt; background:white"><span style="font-family:"Calibri","sans-serif"; color:black">>   = UniqDesugarer</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="margin-left:36.0pt; background:white"><span style="font-family:"Calibri","sans-serif"; color:black">>   | UniqAbsCFlattener</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="margin-left:36.0pt; background:white"><span style="font-family:"Calibri","sans-serif"; color:black">>   | UniqSimplStg</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="margin-left:36.0pt; background:white"><span style="font-family:"Calibri","sans-serif"; color:black">>   | UniqNativeCodeGen</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="margin-left:36.0pt; background:white"><span style="font-family:"Calibri","sans-serif"; color:black">>   ...</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span><span style="color:#282828"></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">OK by me</span><span style="color:#282828"></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span><span style="color:#282828"></span></p>
<p style="margin-left:36.0pt; background:white"><span style="font-family:"Calibri","sans-serif"; color:black">3) Is there a reason for having functions implementing class-methods to be exported? In the case of Unique, there is pprUnique and:</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="margin-left:36.0pt; background:white"><span style="font-family:"Calibri","sans-serif"; color:black">> instance Outputable Unique where</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="margin-left:36.0pt; background:white"><span style="font-family:"Calibri","sans-serif"; color:black">>   ppr = pprUnique</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span><span style="color:#282828"></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">Please don’t change this.  If you want to change how pretty-printing of uniques works, and want to find all the call sites of pprUnique,
 it’s FAR easier to grep for pprUnique than to search for  all calls of ppr, and work out which are at type Unique! 
</span><span style="color:#282828"></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span><span style="color:#282828"></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">(In my view) it’s usually much better not to use type classes unless you actually need overloading.</span><span style="color:#282828"></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span><span style="color:#282828"></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">Simon</span><span style="color:#282828"></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span><span style="color:#282828"></span></p>
<div style="border:none; border-left:solid blue 1.5pt; padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="background:white"><b><span lang="EN-US" style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#282828">From:</span></b><span lang="EN-US" style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#282828">
<a href="mailto:p.k.f.holzenspies@utwente.nl">p.k.f.holzenspies@utwente.nl</a> [<a href="mailto:p.k.f.holzenspies@utwente.nl">mailto:p.k.f.holzenspies@utwente.nl</a>]
<br>
<b>Sent:</b> 18 August 2014 14:50<br>
<b>To:</b> Simon Peyton Jones; <a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
<b>Subject:</b> RE: Unique as special boxing type & hidden constructors</span><span style="color:#282828"></span></p>
</div>
</div>
<p class="MsoNormal" style="background:white"><span style="color:#282828"> </span></p>
<div>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">Dear Simon, et al,</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">Looking at Unique, there are a few more design choices that may be outdated, and since I'm polishing things now, anyway, I figured I could update it on more fronts.</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">1) There is a #ifdef define(__GLASGOW_HASKELL__), which confused me somewhat. Similar things occur elsewhere in the code. Isn't the assumption that GHC is being used?
 Is this old portability stuff that may be removed?</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">2) Uniques are produced from a Char and an Int. The function to build Uniques (mkUnique) is not exported, according to the comments, so as to see all characters used.
 Access to these different "classes" of Uniques is given through specialised mkXXXUnique functions. Does anyone have a problem with something like:</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">> data UniqueClass</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">>   = UniqDesugarer</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">>   | UniqAbsCFlattener</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">>   | UniqSimplStg</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">>   | UniqNativeCodeGen</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">>   ...</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">and a public (i.e. exported) function:</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">> mkUnique :: UniqueClass -> Int -> Unique</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">? The benefit of this would be to have more (to my taste) self-documenting code and a greater chance that documentation is updated (the list of "unique supply characters"
 in the comments is currently outdated).</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">3) Is there a reason for having functions implementing class-methods to be exported? In the case of Unique, there is pprUnique and:</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">> instance Outputable Unique where</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">>   ppr = pprUnique</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">Here pprUnique is exported and it is used in quite a few places where it's argument is unambiguously a Unique (so it's not to force the type) *and* "ppr" is used for all
 kinds of other types. I'm assuming this is an old choice making things marginally faster, but I would say cleaning up the API / namespace would now outweigh this margin.</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">​</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">I will also be adding Haddock-comments, so when this is done, a review would be most welcome (I'll also be doing some similar transformations to other long-since-untouched-code).</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">Regards,</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">Philip</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<div>
<div class="MsoNormal" align="center" style="text-align:center; background:white">
<span style="font-family:"Calibri","sans-serif"; color:#282828">
<hr size="3" width="98%" align="center">
</span></div>
<div id="divRplyFwdMsg">
<p class="MsoNormal" style="background:white"><b><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:black">Van:</span></b><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:black"> Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com">simonpj@microsoft.com</a>><br>
<b>Verzonden:</b> maandag 18 augustus 2014 00:11<br>
<b>Aan:</b> Holzenspies, P.K.F. (EWI); <a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
<b>Onderwerp:</b> RE: Unique as special boxing type & hidden constructors</span><span style="font-family:"Calibri","sans-serif"; color:#282828">
</span><span style="color:#282828"></span></p>
<div>
<p class="MsoNormal" style="background:white"><span style="font-family:"Calibri","sans-serif"; color:#282828"> </span><span style="color:#282828"></span></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">Re (1) I think this is a historical.  A newtype wrapping an Int should be fine.  I’d be ok with that change.
</span><span style="color:#282828"></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span><span style="color:#282828"></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">Re (2), I think your question is: why does module Unique export the data type Unique abstractly, rather than exporting both the data
 type and its constructor.  No deep reason here, but it guarantees that you can only *<b>make</b>* a unique from an Int by calling ‘mkUniqueGrimily’, which signals clearly that something fishy is going on.  And rightly so!</span><span style="color:#282828"></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span><span style="color:#282828"></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">Simon</span><span style="color:#282828"></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span><span style="color:#282828"></span></p>
<div style="border:none; border-left:solid blue 1.5pt; padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="background:white"><b><span lang="EN-US" style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#282828">From:</span></b><span lang="EN-US" style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#282828"> ghc-devs
 [<a href="mailto:ghc-devs-bounces@haskell.org">mailto:ghc-devs-bounces@haskell.org</a>]
<b>On Behalf Of </b><a href="mailto:p.k.f.holzenspies@utwente.nl">p.k.f.holzenspies@utwente.nl</a><br>
<b>Sent:</b> 15 August 2014 11:53<br>
<b>To:</b> <a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
<b>Subject:</b> Unique as special boxing type & hidden constructors</span><span style="color:#282828"></span></p>
</div>
</div>
<p class="MsoNormal" style="background:white"><span style="color:#282828"> </span></p>
<div>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">Dear all,</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">I'm working with Alan to instantiate everything for Data.Data, so that we can do better SYB-traversals (which should also help newcomers significantly to get into the
 GHC code base). Alan's looking at the AST types, I'm looking at the basic types in the compiler.</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">Right now, I'm looking at Unique and two questions come up:</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">> data Unique = MkUnique FastInt</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">1) As someone already commented: Is there a specific reason (other than history) that this isn't simply a newtype around an Int? If we're boxing anyway, we may as well
 use the default Int boxing and newtype-coerce to the specific purpose of Unique, no?</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">2) As a general question for GHC hacking style; what is the reason for hiding the constructors in the first place?</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">I understand about abstraction and there are reasons for hiding, but there's a "public GHC API" and then there are all these modules that people can import at their own
 peril. Nothing is guaranteed about their consistency from version to version of GHC. I don't really see the point about hiding constructors (getting in the way of automatically deriving things) and then giving extra functions like (in the case of Unique):</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">> getKeyFastInt (MkUnique x) = x</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">> mkUniqueGrimily x = MkUnique (iUnbox x)</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="margin-bottom:12.0pt; background:white"><span style="font-family:"Calibri","sans-serif"; color:black">I would propose to just make Unique a newtype for an Int and making the constructor visible.</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">Regards,</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black">Philip</span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
<p style="background:white"><span style="font-family:"Calibri","sans-serif"; color:black"> </span><span style="font-family:"Calibri","sans-serif"; color:#282828"></span></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>