<div dir="ltr">Shot in the dark: Would extensions like QuantifiedConstraints or ImplicationConstraints, if implemented, help with <span class="gmail-im"><span>ImpredicativeTypes?</span></span></div><div class="gmail_extra"><br><div class="gmail_quote">2016-09-30 15:29 GMT+00:00 Simon Peyton Jones via ghc-devs <span dir="ltr"><<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div link="blue" vlink="purple" lang="EN-GB">
<div class="m_-1204540268970108770WordSection1">
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif">Alejandro: excellent point. I mis-spoke before.  In my proposal we WILL allow types like (Tree (forall a. a->a)).<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif">I’m trying to get round to writing a proposal (would someone else like to write it – it should be short), but the idea is this:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif"><u></u> <u></u></span></p>
<p class="MsoNormal" style="margin-left:18.0pt"><b><span style="font-family:"Calibri",sans-serif">When you have -XImpredicativeTypes<u></u><u></u></span></b></p>
<p class="m_-1204540268970108770MsoListParagraph" style="margin-left:54.0pt">
<u></u><span style="font-family:Symbol"><span>·<span style="font:7.0pt "Times New Roman"">        
</span></span></span><u></u><b><span style="font-family:"Calibri",sans-serif">You can write a polytype in a visible type argument; eg.  f @(forall a. a->a)<u></u><u></u></span></b></p>
<p class="m_-1204540268970108770MsoListParagraph" style="margin-left:54.0pt">
<u></u><span style="font-family:Symbol"><span>·<span style="font:7.0pt "Times New Roman"">        
</span></span></span><u></u><b><span style="font-family:"Calibri",sans-serif">You can write a polytype as an argument of a type in a signature  e.g.  f :: [forall a. a->a] -> Int<u></u><u></u></span></b></p>
<p class="MsoNormal" style="margin-left:18.0pt"><b><span style="font-family:"Calibri",sans-serif"><u></u> <u></u></span></b></p>
<p class="MsoNormal" style="margin-left:18.0pt"><b><span style="font-family:"Calibri",sans-serif">And that’s all.  A unification variable STILL CANNOT be unified with a polytype.  The only way you can call a polymorphic function at
 a polytype is to use Visible Type Application.<u></u><u></u></span></b></p>
<p class="MsoNormal" style="margin-left:18.0pt"><b><span style="font-family:"Calibri",sans-serif"><u></u> <u></u></span></b></p>
<p class="MsoNormal" style="margin-left:18.0pt"><b><span style="font-family:"Calibri",sans-serif">So using impredicative types might be tiresome.  E.g.<u></u><u></u></span></b></p>
<p class="m_-1204540268970108770Code" style="margin-left:54.0pt"><b><span>  type SID = forall a. a->a<u></u><u></u></span></b></p>
<p class="m_-1204540268970108770Code" style="margin-left:54.0pt"><b><span><u></u> <u></u></span></b></p>
<p class="m_-1204540268970108770Code" style="margin-left:54.0pt"><b><span>  xs :: [forall a. a->a]<u></u><u></u></span></b></p>
<p class="m_-1204540268970108770Code" style="margin-left:54.0pt"><b><span>  xs = (:) @SID id ( (:) @SID id ([] @ SID))<u></u><u></u></span></b></p>
<p class="MsoNormal" style="margin-left:18.0pt"><b><span style="font-family:"Calibri",sans-serif"><u></u> <u></u></span></b></p>
<p class="MsoNormal" style="margin-left:18.0pt"><b><span style="font-family:"Calibri",sans-serif">In short, if you call a function at a polytype, you must use VTA.  Simple, easy, predictable; and doubtless annoying.  But possible</span></b><span style="font-family:"Calibri",sans-serif">.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif">Simon<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif"><u></u> <u></u></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 style="font-size:11.0pt;font-family:"Calibri",sans-serif" lang="EN-US">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" lang="EN-US"> Alejandro Serrano Mena [mailto:<a href="mailto:trupill@gmail.com" target="_blank">trupill@gmail.com</a>]
<br>
<b>Sent:</b> 26 September 2016 08:13<span class=""><br>
<b>To:</b> Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>><br>
<b>Cc:</b> <a href="mailto:ghc-users@haskell.org" target="_blank">ghc-users@haskell.org</a>; <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<b>Subject:</b> Re: Getting rid of -XImpredicativeTypes<u></u><u></u></span></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:12.0pt;margin-left:0cm">
What would be the story for the types of the arguments. Would I be allowed to write the following?<u></u><u></u></p>
</div><div><div class="h5">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:12.0pt;margin-left:0cm">
> f (lst :: [forall a. a -> a]) = head @(forall a. a -> a) lst 3<u></u><u></u></p>
</div></div></div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
Regards,<u></u><u></u></p>
</div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
Alejandro<u></u><u></u></p>
</div><div><div class="h5">
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<u></u> <u></u></p>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
2016-09-25 20:05 GMT+02:00 Simon Peyton Jones via ghc-devs <<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a>>:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<p class="MsoNormal">Friends<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">GHC has a flag -XImpredicativeTypes that makes a half-hearted attempt to support impredicative polymorphism.  But it is vestigial…. if it works, it’s really a fluke.  We don’t really
 have a systematic story here at all.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">I propose, therefore, to remove it entirely.  That is, if you use -XImpredicativeTypes, you’ll get a warning that it does nothing (ie. complete no-op) and you should remove it.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Before I pull the trigger, does anyone think they are using it in a mission-critical way?<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Now that we have Visible Type Application there is a workaround: if you want to call a polymorphic function at a polymorphic type, you can explicitly apply it to that type.  For
 example:<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p>{-# LANGUAGE ImpredicativeTypes, TypeApplications, RankNTypes #-}<u></u><u></u></p>
<p>module Vta where<u></u><u></u></p>
<p>  f x = id @(forall a. a->a) id @Int x<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">You can also leave out the @Int part of course.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Currently we have to use -XImpredicativeTypes to allow the @(forall a. a->a).    Is that sensible?  Or should we allow it regardless?   I rather think the latter… if you have Visible
 Type Application (i.e. -XTypeApplications) then applying to a polytype is nothing special.   So I propose to lift that restriction.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">I should go through the GHC Proposals Process for this, but I’m on a plane, so I’m going to at least start with an email.<u></u><u></u></p>
<p class="MsoNormal"><span style="color:#888888"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#888888">Simon<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
______________________________<wbr>_________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.haskell.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-devs&data=01%7C01%7Csimonpj%40microsoft.com%7Cd4eb1fd61d0148cea9f508d3e5dca6fe%7C72f988bf86f141af91ab2d7cd011db47%7C1&sdata=ZM3djztmpA09J6x1DmmV0LEeftsA1FhjPhjwLuG5w%2FE%3D&reserved=0" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/ghc-devs</a><u></u><u></u></p>
</blockquote>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div></div></div>
</div>
</div>

<br>______________________________<wbr>_________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/ghc-devs</a><br>
<br></blockquote></div><br></div>