OK, I am rephrasing it a bit then :)
I definitely don't think this would be trivial to implement. However, I'd expect a decent solution to this problem, not to have special combinators to describe relations between data types, but let the user model their data using plain haskell data types, and infer the associated table structure just by looking at the data types.

I'll give this a harder thought once I find the time. There is the huge barrier of TH, stopping me from playing with things like this. 

Anyway, have fun! :)

On 29 September 2010 10:41, Chris Eidhof <chris@eidhof.nl> wrote:
On 28 sep 2010, at 17:33, Ozgur Akgun wrote:

> How do you define relationships between data types?
>
> Well, why is it any different from other fields? From one of your examples [1], I'd expect you to have a list of questions in the Quiz data type, and if necessary, a quiz field in the Question data type. This might be a bit tricky but certainly achievable [2].

This is really tricky. For example, consider storing a large tree in the database:

> data Tree = Node Int Tree Tree | Leaf Int

This means you need to read the entire tree from the database. Or consider cyclic datastructures (such as the example you gave). How do you store this? The only way to inspect this is using a library like data-reify [1].

I think the problem might be a bit harder than you suspect.

Another way to solve it is using Sebastiaan Visser's framework, described in his paper [2], but that's also rather complicated.

-chris

[1]: http://hackage.haskell.org/package/data-reify
[2]: http://github.com/downloads/sebastiaanvisser/msc-thesis/wgp10-genstorage.pdf



--
Ozgur Akgun