stefan-hoeck / idris2-elab-util

Utilities and documentation for exploring idirs2's new elaborator reflection.
BSD 2-Clause "Simplified" License
76 stars 16 forks source link

What does the %runElab directive do #10

Closed MakitaToki closed 3 years ago

MakitaToki commented 3 years ago

In the article Enum1.md, is the following code generated by the line %runElab (mkEnum "Gender"["Female","Male","NonBinary"]) ? I write the line %runElab (mkEnum "Gender"["Female","Male","NonBinary"]), but no changes happen.

export
Eq Gender where
  Female     == Female     = True
  Male       == Male       = True
  NonBinary  == NonBinary  = True
  _          == _          = False
stefan-hoeck commented 3 years ago

%runElab runs an elaborator script. In the above example, this results in a new data type called Gender with nullary constructors Male, Female, and NonBinary being defined. In order to make the changes visible, we implement an Eq instance for this new data type.

You can also try the following: Remove the line with %runElab from Enum1.md and try to typecheck the file. When Idris comes to the definition of Eq Gender, it will complain about no data type called Gender being in scope.

I updated Enum1.md with some clarifying remarks. Feel free to ask, if things remain unclear.

Here's a summary of the pieces interacting with each other:

MakitaToki commented 3 years ago

Thanks for your detailed explanation.