Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra parameters in instances cause bad errors #446

Open
zstone1 opened this issue Sep 20, 2024 · 0 comments
Open

Extra parameters in instances cause bad errors #446

zstone1 opened this issue Sep 20, 2024 · 0 comments

Comments

@zstone1
Copy link

zstone1 commented Sep 20, 2024

A bug I am encountering when working with topologicalType vs pseudoMetricType where the metric has an extra parameter:

HB.mixin Record Basic T := { prop1 : forall (x : T), x = x }.

HB.structure Definition JustBasic := {T of Basic T}.

HB.mixin Record WithExtraParam {R : Type} T of Basic T := {
  prop2 : forall (r : R) (x : T), x = x
}. 

HB.structure Definition WithExtra {R} := {T of WithExtraParam R T & Basic T}.

HB.factory Record BasicAlt T := { prop3 : forall (x:T), x = x }.

HB.builders Context T of BasicAlt T.
HB.instance Definition _ := Basic.Build T prop3.
HB.instance Definition _ {R} := @WithExtraParam.Build R T (fun=>prop3).
HB.end.

HB.instance Definition _ := @BasicAlt.Build bool (fun=> erefl).

The factory and builder work fine, but I get

take run out of list items

as the error, which is pretty meaningless to me. I can tell that the issue is with the R parameter of HB.instance Definition _ {R} .

Ideally, I want HB to know how to build a WithExtraParam R when it encounters one, but not try to build one right now.
Which is what I would get if I did

HB.builders Context R T of BasicAlt R T.
HB.instance Definition _ := Basic.Build T prop3.
HB.instance Definition _ := @WithExtraParam.Build R T (fun=>prop3).
HB.end.

HB.instance Definition _ {R} := @BasicAlt.Build R bool (fun=> erefl).

but now I can't build my Basic without an R.

The workaround for now seems to be to have two factories, R-dependent and R-independent portions. Then build an instance for both like

HB.factory Record BasicAlt T := { prop3 : forall (x:T), x = x }.

HB.builders Context T of BasicAlt T.
HB.instance Definition _ := Basic.Build T prop3.
HB.end.

HB.factory Record BasicAltWithParam R T of BasicAlt T := {}.
HB.builders Context R T of BasicAltWithParam R T.
HB.instance Definition _ := @WithExtraParam.Build R T (fun _ _ => erefl).
HB.end.

HB.instance Definition _ := @BasicAlt.Build bool (fun=> erefl).
HB.instance Definition _ {R} := @BasicAltWithParam.Build R bool.

Ideally, I'd like it to infer those extra parameters to the instances. But I'm fine with this split solution in the interim. But then the hb.end or the hb.instance in the first example should fail. And of course the current error message is not great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant