In Haskell, generic programming can be done in several ways:
by deriving GHC.Generics.Generic, writing instances on the Rep, and converting between Rep a and a at runtime
by using TemplateHaskell's reify to obtain the definition of a datatype, and generating the appropriate code at compile-time
by deriving Data.Data, and writing functions which match on the type of the fields at runtime
I propose to use a different way:
by using a type-aware macro to match on Rep a, and generating the appropriate code at compile-time
This either requires:
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.
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.
In Haskell, generic programming can be done in several ways:
GHC.Generics.Generic
, writing instances on the Rep, and converting betweenRep a
anda
at runtimereify
to obtain the definition of a datatype, and generating the appropriate code at compile-timeData.Data
, and writing functions which match on the type of the fields at runtimeI propose to use a different way:
Rep a
, and generating the appropriate code at compile-timeThis either requires:
(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.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 thedatatype
declaration to fill up that MonoMap.