[Haskell-cafe] Explicit type signatures and wrappers / impedance-matching

Richard Eisenberg lists at richarde.dev
Tue Feb 22 20:54:54 UTC 2022



> On Feb 22, 2022, at 2:42 PM, Benjamin Redelings <benjamin.redelings at gmail.com> wrote:
> Then, in order to handle the difference between these two types, we call `tcSubTypeSigma actual_type more_quantified_type`, which
> 
> ... It may (I think) eliminate predicates by defaulting, and it can eliminate types by substituting an ANY type, at least sometimes.  This wrapper is stored inside abe_wrap field of ABE objects, inside the abs_exports field of the AbsBinds.
> 
> 

I don't think this step ever does defaulting or uses Any.

> 
> II. I am still not completely sure how the wrapper is actually applied in code generation, or how the wrapper is computed from the two types.  But, I'm not quite done reading yet.
> 
> For example, in the case above, suppose that `tuple` represents all combined binders inside the AbsBinds, and is quantified by ALL the type variables and ALL the (given) dictionaries.  One approach would be something like:
> 
> tuple = /\a./\b.\(dNum :: Num b). let ...CODE... in (f,g)
> 
> f' = /\a./\b.\(dNum :: b). case (tuple @a @b dNum) of f
> 
> f = /\a. f' @a @ANY dNum = apply wrapper to f' ?
> 
> In that approach, then we would FIRST extract an "f'" from the tuple without applying any wrapper.  Then, SECOND, we would SECOND apply the wrapper to f' to get f.
> 
> 
I don't follow here -- sorry. I think you have some typos in your example (for example, there is no -> after 'of' in your 'case', and I see two =s on the last line), and I can't quite figure out what you mean. 

> 
> III. I am also still working through tcMonoBinds.  I'm curious what happens in a pattern binding, when the pattern has a type signature with predicates:
> 
> f:: forall a.Num a -> a->a->a
> 
> (f,g) = ...rhs...
> 
> It looks like the type signature for gets instantiated on the LHS, and.... I presume the predicate Num a is added to the local instance environment, just like if f was instantiated on the RHS?   I will think about this more...
> 
Not sure what you mean here. :( For a pattern binding, I'm pretty sure all the signature does is set what will happen if GHC looks up a symbol's type when processing the RHS.

> 
> Anyway, thanks for the encouragement.  I am not stuck, yet...
> 
> All this does make me think that, perhaps, some kind of updated version of Typing Haskell in Haskell would be appropriate.  I'm not sure how much of this is in the Report, either.
> 
Little, if any, of this is in the Report, and it's unclear to me whether that's a good or a bad thing.

An up-to-date description of all of this would be lovely! But is it worth it? Especially when this all will continue to change?

Keep plugging away! You're definitely working in the right direction.

Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20220222/7b75d1ea/attachment.html>


More information about the Haskell-Cafe mailing list