<div dir="ltr"><div>Just to clarify, for exported names ignore the unique value completely and use module name + occurrence name. In your case that is the idStableName field.</div><div>For non exported names use idStableName + idUnique.</div><div><br></div><div>I'll also check your project.</div><div><br></div><div>Cheers,</div><div>Csaba<br></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Nov 30, 2018 at 12:23 PM Christopher Done <<a href="mailto:chrisdone@gmail.com">chrisdone@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Csaba,<br>
<br>
Thanks for your answer. I think I'm doing something very similar to<br>
you. I'm converting the GHC AST to my own AST with this code:<br>
<br>
<a href="https://gist.github.com/chrisdone/96e228f12bdbc3c43d06718467e69029#file-main-hs-L815--L915" rel="noreferrer" target="_blank">https://gist.github.com/chrisdone/96e228f12bdbc3c43d06718467e69029#file-main-hs-L815--L915</a><br>
<br>
I have an Id type that's similar to yours,<br>
<br>
    data Id = Id<br>
      { idStableName :: {-# UNPACK #-}!ByteString<br>
      , idUnique :: {-# UNPACK #-}!Unique<br>
      , idCategory :: !Cat<br>
      } deriving (Generic, Data, Typeable, Eq, Show, Ord)<br>
<br>
And (I think) I've solved my first question by adding that category<br>
field, which can be one of:<br>
<br>
    data Cat<br>
      = ValCat<br>
      | DataCat<br>
      | ClassCat<br>
      deriving (Generic, Data, Typeable, Eq, Show, Ord)<br>
<br>
When an expression like this comes along:<br>
<br>
    AppE<br>
      (AppE<br>
         (VarE<br>
            (Id<br>
               { idStableName = "main:Main.C:Wiggle"<br>
               , idUnique = Unique 8214565720323785205<br>
               , idCategory = ClassCat<br>
               }))<br>
         (TypE (Typ "Int")))<br>
      (VarE<br>
         (Id<br>
            { idStableName = "main:Main.$cfoo"<br>
            , idUnique = Unique 6989586621679010971<br>
            , idCategory = ValCat<br>
            }))<br>
      VarE<br>
      (Id<br>
         { idStableName = "main:Main.$cbar"<br>
         , idUnique = Unique 6989586621679010975<br>
         , idCategory = ValCat<br>
         })<br>
<br>
It constructs a class dictionary for the class "Wiggle", with the<br>
methods "foo" and "bar", and the interpreter treats Wiggle as a regular<br>
data constructor. Meanwhile, when an nth class method (like<br>
"main:Main.$cfoo") is resolved, it produces a Method, and when applying<br>
a method to a data constructor Wiggle, the interpreter access the nth<br>
slot.<br>
<br>
That works out. An example is here:<br>
<br>
<a href="https://gist.github.com/chrisdone/771292425a9f1bb428ef4eda3779dc40" rel="noreferrer" target="_blank">https://gist.github.com/chrisdone/771292425a9f1bb428ef4eda3779dc40</a><br>
<br>
See how the "main:Main.$fWiggleInt" is resolved to the above dictionary.<br>
<br>
As for the second question, and your answer, I am a bit puzzled, maybe<br>
you can clarify?<br>
<br>
> Regarding the names you can use qualified (module + occ) names for<br>
> exported ids. (see: Var.isExportedId).<br>
><br>
> For non exported Id's you can rely on unique values.<br>
<br>
You say that for exported names I can rely soley on the stable name<br>
(package+module+ident), and for internal IDs I can use the Unique?<br>
<br>
I believe that's what I'm reproducing, here. The following name isn't<br>
resolved:<br>
<br>
    Id<br>
      { idStableName = "base:GHC.Base.$fApplicativeIO"<br>
      , idUnique = Unique 8214565720323784738<br>
      , idCategory = ValCat<br>
      }<br>
<br>
If I list all bindings available, I find this name, which has a<br>
different Unique:<br>
<br>
    Id<br>
      { idStableName = "base:GHC.Base.$fApplicativeIO"<br>
      , idUnique = Unique 8214565720323793553 <--- differing<br>
      , idCategory = ValCat<br>
      }<br>
<br>
So if I were to apply your approach and do exported lookups by<br>
idStableName, and local-module lookups (beta substitution) by Unique, it<br>
should work out.<br>
<br>
The question is whether "base:GHC.Base.$fApplicativeIO" is actually<br>
exported -- I presume all instance dictionaries are exported.<br>
<br>
I will give it a try and report back to you!<br>
<br>
Cheers!<br>
</blockquote></div>