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

Type_class: recursive instantiation #15

Open
5 tasks
cognivore opened this issue Feb 28, 2023 · 0 comments
Open
5 tasks

Type_class: recursive instantiation #15

cognivore opened this issue Feb 28, 2023 · 0 comments

Comments

@cognivore
Copy link
Contributor

Why does it have to be done?

For the following classes:

defclass A do
  def f(x), do: x
end

defclass B do
  def g(_x, y), do: y
end

defclass C do
  extend A
  extend B
  def h(x, _y), do: x
end

Being able to write the following instance:

definst C, for: X do
  def f(x), do: x.c
  def h(x, y), do: {x.c, y}
end

instead of

definst B, for: X
definst A, for: X do
  def f(x), do: x.value
end
definst C, for: X do
  def h(x, y), do: {x.value, y}
end

is actually a huge boost in ergonomics! Languages like Lean4 allow for it and it feels really good to be able to have the compiler resolve the typeclass dependencies and inject correct functions into correct places.

see here.

How do you think does it have to be done?

  • Extract local functions with Macro.prewalk in definst
  • Recursively build a list of "buckets" (the functions that are required to be provided by the classes a given class extends).
  • Check which buckets are filled entirely by local functions.
  • For each of such bucket, recursively call definst.
  • If you have the time, optimise the amount of recursion in this implementation plan! If not, ship it :)

What do you think needs to be figured out for it to be done?

No response

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