jeudi 12 mars 2015

Introspecting function names in a GHC module

Is there a way in the Glasgow Haskell Compiler to introspect the names of all functions in a module?


I am trying to create an automatic database migration system that, given the names of migration modules, introspects the names of the functions inside and calls them one at a time.


Something like



doMigrations("Migrations.M_2015")
doMigrations("Migrations.M_2016")
-- ...


where Migration.M_2015 contains



module Migration.M_2015
where

migration_2015_01_02 :: DbConnection -> Status
migration_2015_01_02 connection =
-- ...


Each doMigration will reflect the names of the migration functions in its module and only call those that have not been run before (names saved in a DB table). This will only be called at application start-up, so performance is not a big issue. The reflection can occur at either compile-time or run-time.






Aucun commentaire:

Enregistrer un commentaire