Re: [Haskell-cafe] Using Template Haskell to make type-safe database access

2008-05-14 Thread Mads Lindstrøm
Hi Bjorn Bringert wrote: Mads: Preparing the statement and asking the DB about the type at compile is a great idea! I've never thought of that. Please consider completing this and packaging it as a library. Thanks for the nice remark. And I will begin completing the idea, as soon I have

Re: [Haskell-cafe] Using Template Haskell to make type-safe database access

2008-05-08 Thread Wouter Swierstra
Hi Mads, Not only pictures, but also code can say more than a thousands words. Therefore, I have been implementing a proof of concept. The code is attached in two files. Nice! I have to admit, it's much nicer than I expected it to be. Just out of curiousity, what happens when you write:

Re: [Haskell-cafe] Using Template Haskell to make type-safe database access

2008-05-08 Thread Mads Lindstrøm
Hi Wouter, Wouter Swierstra wrote: Nice! I have to admit, it's much nicer than I expected it to be. Just out of curiousity, what happens when you write: selectTupleList :: Connection - IO [Integer] instead of selectTupleList :: Connection - IO [(Integer, String, String)] What

Re: [Haskell-cafe] Using Template Haskell to make type-safe database access

2008-05-07 Thread Mads Lindstrøm
Hi Wouter Wouter Swierstra wrote: Here's a concrete example. Suppose you have a query q that, when performed, will return a table storing integers. I can see how you can ask the SQL server for the type of the query, parse the response, and compute the Haskell type [Int]. I'm not sure

Re[2]: [Haskell-cafe] Using Template Haskell to make type-safe database access

2008-05-07 Thread Bulat Ziganshin
Hello Mads, Thursday, May 8, 2008, 1:24:05 AM, you wrote: also because TH is difficult. At least TH was difficult for me. It might just be because I have never worked with anything like TH before (have no, TH is dificult by itself. if you have spare time - read about metalua, which implements

Re: [Haskell-cafe] Using Template Haskell to make type-safe database access

2008-05-06 Thread Wouter Swierstra
Hi Mads, I think there may a bit of problem with the approach you suggest: as the type returned by the query is computed by the SQL server (if I understand you correctly), it's very hard to do anything with the result of the query - the Haskell compiler has no idea what type the result has, so

Re: [Haskell-cafe] Using Template Haskell to make type-safe database access

2008-05-05 Thread Wouter Swierstra
Hi Mads, I was wondering if anybody had experimented with using Template Haskell (TH) and ordinary SQL to make type-safe database access? I know HaskellDB, for example, does something quite similar. There's a preprocessor that generates a Haskell file with a Haskell representation of

Re: [Haskell-cafe] Using Template Haskell to make type-safe database access

2008-05-05 Thread Mads Lindstrøm
Hi, Wouter Swierstra wrote: Hi Mads, I was wondering if anybody had experimented with using Template Haskell (TH) and ordinary SQL to make type-safe database access? I know HaskellDB, for example, does something quite similar. There's a preprocessor that generates a Haskell file

[Haskell-cafe] Using Template Haskell to make type-safe database access

2008-05-02 Thread Mads Lindstrøm
Hi, 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