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

generic programming via type-case #218

Open
gelisam opened this issue Aug 5, 2023 · 0 comments
Open

generic programming via type-case #218

gelisam opened this issue Aug 5, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@gelisam
Copy link
Owner

gelisam commented Aug 5, 2023

In Haskell, generic programming can be done in several ways:

  1. by deriving GHC.Generics.Generic, writing instances on the Rep, and converting between Rep a and a at runtime
  2. by using TemplateHaskell's reify to obtain the definition of a datatype, and generating the appropriate code at compile-time
  3. by deriving Data.Data, and writing functions which match on the type of the fields at runtime

I propose to use a different way:
4. by using a type-aware macro to match on Rep a, and generating the appropriate code at compile-time

This either requires:

  1. adding a built-in type-pattern which would look like (datatype "Person" (list (datatype-constructor "person" 'person))), where 'person can be used in the generated code as a value of type (-> String Integer (Person)), so that another type-aware macro may match on that type.
  2. implementing monotonously-increasing maps #168, then defining the datatype type-pattern in #lang prelude so that it looks up the relevant information in a MonoMap in order to implement the above pattern, and also extend the datatype declaration to fill up that MonoMap.
@gelisam gelisam added the enhancement New feature or request label Aug 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant