Jason Kinzer a écrit :
By the way, as I'm doing OCaml binding work, I was looking at how OCaml could be used to design queries in a statically type safe way. I stumbled on this:
http://eigenclass.org/hiki/addressing-orm-problem-typed-relational-algebra
How hard would it be to implement a query compiler from such a typed relational algebra?
Hmmmm, well, it doesn't sound particularly easy. You basically take whatever effort would be involved with compiling down from a string-based form (say, what Hibernate QL does) and then add on top of that magic to get your relational algebra representation to play nicely with the Ocaml type system.
I think this is the part that has already been done by Mauricio in the link above. http://eigenclass.org/repos/gitweb?p=relational.git;a=summary http://eigenclass.org/hiki/typed-relational-algebra-in-OCaml
(Basically you're creating an embedded DSL). Are you considering targetting SQL or MAL?
I'm targetting MAL.
In a sense MAL seems ideal since the BAT operators implement a relational algebra already, so it would be a fairly direct mapping.
This still needs to be checked out thoroughly, but yes, that's the idea.
Well, except then you're inventing the concept of tables from scratch. In any case, I suspect the main difficulty here will be in the frontend... BTW, Scala has a SQL DSL as well you might want to check out for further inspiration (it's taking heavy advantage of implicits, which are sort of like type classes - Ocaml doesn't have these of course, but maybe still interesting).
I do not doubt it's interesting. But SQL is not my main goal here. If Mauricio's relational algebra is lean enough, the balance between static type checking and SQL's quirks will be in favour of Mauricio's work. Besides, It would seem to overlap with Mauricio's work which already provides some parsing from his OCaml algebra to SQL. But the thing is, you've got the SQL string created at OCaml compile time. What would be nice is to have the SQL -> MAL compilation also happen at the same time you compile the OCaml program. (Moreover, it seems to me that MAL comes in two flavour: a human-readable one and a machine readable one. Is that correct? If yes, I'm aiming at the machine readable one.) How easy would that be? Do you need a running embedded server for that, or simply a subset of the functionalities of the MonetDB shared libraries? -- Guillaume Yziquel http://yziquel.homelinux.org/