gelisam / klister

an implementation of stuck macros
BSD 3-Clause "New" or "Revised" License
134 stars 11 forks source link

generic programming via type-case #218

Open gelisam opened 1 year ago

gelisam commented 1 year ago

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:

  1. 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 #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.