Skip to content

Generate typeclass instances#175

Merged
just95 merged 74 commits into
mainfrom
issue-150
Sep 29, 2020
Merged

Generate typeclass instances#175
just95 merged 74 commits into
mainfrom
issue-150

Conversation

@MajaRet
Copy link
Copy Markdown
Contributor

@MajaRet MajaRet commented Aug 26, 2020

Issue

Closes #150
Closes #151

Description of the Change

The compiler now generates Normalform and ShareableArgs instances for user-defined data types.

In order to properly handle a program, it needs to be normalized first so that handlers do not have to consider effects in the components of data structures.
To be able to perform this normalization, a data type (and its argument types) must have a Normalform instance.

Furthermore, the share operator requires that the type of the computation that is shares has a ShareableArgs instance so its components can be shared.

Normalform and ShareableArgs instances exist for all Prelude types, but users will also define their own Haskell data types. Therefore, the compiler needs to generate these instances for user-defined data types.

Verification Process

Tests verifying the functionality of generated Normalform instances for various types have been added to the example folder by @marvin2706. Additional functions and tests have been added (in the same modules) to test the generated ShareableArgs instances.

Additional Notes

Because the generation of induction schemes has been moved into its own module, there will likely be merge conflicts with #206.

Maja Reichert added 5 commits August 26, 2020 10:09
During the conversion of a data declaration, a Normalform instance
will be generated.
This commit implements a part of that generator that generates
most of the nf' function. The resulting code is not yet
valid because the type signature is still missing, but if the
type signature is added manually, the generated code is valid.

We are able to consider types with nested recursion and mutually
recursive types, but I have not considered type synonyms yet.
That will also be added later.
@MajaRet MajaRet added enhancement New feature or request Coq Related to Coq back end or base library labels Aug 26, 2020
@MajaRet MajaRet changed the title Issue 150 Generate Normalform instances Aug 26, 2020
Maja Reichert and others added 18 commits August 27, 2020 16:35
The program to generate typeclass instances for user-defined Haskell
types is now more general.
Instances for different typeclasses can now be generated simply by
passing a few parameters, namely:
- The name of the class
- The name of the function provided by the class
- A function that generates appropriate binders and return types
- A function that builds a concrete value of the return type

Currently, only typeclass instances with a certain structure can be
generated (for example, the class can currently only contain one
function), but it should be quite easy to generate instances for
ShareableArgs in addition to Normalform now.
Before the return type of a data constructor is unified with a type
expression, all variables (underscores) in the type expression are
replaced with fresh variables to prevent unification failures.

Additionally, the naming of the instance and top-level functions is
now done outside of a local environment so that those names are
registered globally and no name clashes can occur.
Local functions and variables are still named inside a local environment.
@Daniel-Teut Daniel-Teut requested review from Daniel-Teut and removed request for just95 September 27, 2020 00:43
@MajaRet
Copy link
Copy Markdown
Contributor Author

MajaRet commented Sep 28, 2020

I have implemented the last few suggestions now, but I have also incorporated a few changes into this pull request that were originally required by #202. However, implementing some of the suggestions on what would have essentially been an outdated version of the instance generation would not have made sense. Therefore, those changes have now been added here.

Specifically, the Normalform typeclass is now no longer parameterized over two types (plus Shape and Pos), but only one. So the Normalform class itself, the Prelude instances, and the Normalform-specific functions in the instance generation function have changed to reflect that.

@MajaRet MajaRet requested a review from just95 September 29, 2020 08:13
@just95 just95 merged commit a321281 into main Sep 29, 2020
@just95 just95 deleted the issue-150 branch September 30, 2020 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Coq Related to Coq back end or base library enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generate ShareableArgs instances Generate Normalform instances

4 participants