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

Correctness / Credo: In algae, use the map hack to present a macro st or "structual type", which will take a module and ask for a map with __struct__ field set to an appropriate value #10

Open
4 tasks
cognivore opened this issue Feb 24, 2023 · 1 comment

Comments

@cognivore
Copy link
Contributor

cognivore commented Feb 24, 2023

Why does it have to be done?

We sometimes need to go a bit deeper than 1-deep types when it comes to witchcraft.
But since defdata is evaluated during the final compilation pass (macro expansion step), defdata can't see itself (is non-recursive), nor can it see its neighbours.

However, for every type, we can actually "guess" how progressive typing of it will look at runtime. Elixir mimics "structures" with maps with a field __struct__ set to __MODULE__ where they were declared. For example:

iex(1)> defmodule D, do: defstruct [A, :b]
iex(4)> x = D.__struct__
%D{"Elixir.A": nil, b: nil}
iex(5)> x.__struct__
D

Sadly we can't use a macro here (duh), but we can nonetheless use %Mod{} syntax in typespecs, and disable credo alarm for the %Mod{} usage in typespecs.

How do you think does it have to be done?

  • Check out examples:
    • Of faking a defdata.
    • Of typing a defdata: @type st :: %{required(:__struct__) => OnTheMap.Auth.Identity, optional(any()) => any()}.
  • Use this approach to add st type in defmodule implementation of goo! It won't know about the structure's fields, but it will at least be able to check for presence of the correct __struct__.

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

No response

@cognivore
Copy link
Contributor Author

Since we've done big changes to code generation by making a new-less version of defdata and defsum in Algae Goo recently, we can tack this onto it first.

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