[Haskell-cafe] Using Template Haskell to make type-safe database
mads_lindstroem at yahoo.dk
Fri May 2 16:31:59 EDT 2008
I was wondering if anybody had experimented with using Template Haskell
(TH) and ordinary SQL to make type-safe database access?
To clarify what I am thinking about I will sketch how it could be done.
The TH function should take two inputs. SQL (as a string) and a database
source name (DSN). It should return an IO action as output.
The TH-function should:
1. Connect to the database using the DSN
2. Ask the database which types will be returned from the expression
3. Build an IO action which can be used to execute the SQL at run-time.
The action could return the result as a (lazy) list. Due to step two we
can make the returned values type-safe.
More information about the Haskell-Cafe