<div dir="ltr"><div>My goal is to add type information on hover within `ghcide`. Right now, when you select a variable, we give back the type as reported in the corresponding Var. However, when this type involved a type variable, it misses a lot of important information about the typing context in which we are working. So the goal is to report back some of this typing context.</div><div><br></div><div>Going back to my original example:</div><div><br></div><div>f :: Eq a => [a] -> Bool<br>f xs = xs == []</div><div><br></div><div>It would be great if by hovering over the 'xs', one would get '[a] where Eq a', or some other representation of the known constraints.</div><div><br></div><div>Since this is intended to be a help for the programmer, it doesn't really matter whether we get "too many" constraints (for example, if we had "Ord a" it's OK to get "Eq a" too, since that's interesting constraint information).</div><div><br></div><div>Right now I am working with TypecheckModules most of the time.</div><div><br></div><div>Regards,</div><div>Alejandro<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">El jue., 16 ene. 2020 a las 19:47, Simon Peyton Jones (<<a href="mailto:simonpj@microsoft.com">simonpj@microsoft.com</a>>) escribió:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-GB">
<div class="gmail-m_4730567687234897414WordSection1">
<p class="MsoNormal">There is definitely no pure way to get from ‘a’ to its constraints.<u></u><u></u></p>
<ul style="margin-top:0cm" type="disc">
<li class="gmail-m_4730567687234897414MsoListParagraph" style="margin-left:0cm">It is far from clear what “its constraints” are.   Is (C a b) such a constraint?  C [a] b?  What about superclasses?<u></u><u></u></li><li class="gmail-m_4730567687234897414MsoListParagraph" style="margin-left:0cm">Constraints vary depending on where  you are.  GADT matches can bring into scope extra constraints on existing type variables.<u></u><u></u></li></ul>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">So as Ben says, to give a sensible response you’ll need to explain more about your goal<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Simon<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div style="border-color:currentcolor currentcolor currentcolor blue;border-style:none none none solid;border-width:medium medium medium 1.5pt;padding:0cm 0cm 0cm 4pt">
<div>
<div style="border-color:rgb(225,225,225) currentcolor currentcolor;border-style:solid none none;border-width:1pt medium medium;padding:3pt 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> ghc-devs <<a href="mailto:ghc-devs-bounces@haskell.org" target="_blank">ghc-devs-bounces@haskell.org</a>>
<b>On Behalf Of </b>Alejandro Serrano Mena<br>
<b>Sent:</b> 16 January 2020 16:19<br>
<b>To:</b> GHC developers <<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a>><br>
<b>Subject:</b> Find constraints over type<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
Dear GHC devs,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
I am trying to figure out a way to obtain the constraints that hold over a type. Let me give you an example: suppose that I write the following function:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
f :: Eq a => [a] -> Bool<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
f xs = xs == []<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
If I ask for the type of the Var ' xs', I get back '[a]'. This is correct, but I am missing the crucial information that '[a]' must be Eq.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
Is there an easy way to get it? It seems that 'varType' doesn't give me enough information.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
Regards,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
Alejandro<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>

</blockquote></div>