ekmett / tables

Deprecated because of
https://github.com/ekmett/tables/issues/15
Other
78 stars 13 forks source link

Towards defining an inner join between two tables. #17

Closed MetaMemoryT closed 10 years ago

MetaMemoryT commented 11 years ago

I want to define an innerJoin between two tables, something like:

innerJoin ::
    (Tabular t1
    ,Tabular t2
    ,Tabular t3
    ,PKT t1 ~ PKT t2
    ,PKT t2 ~ PKT t3
    ,PKT t1 ~ PKT t3) =>
        (t1 -> t2 -> Bool) ->
    Table t1 -> Table t2 -> Table t3

How could the result t3 have a Tabular instance automatically derived for it?

How could the lenses that are used to manipulate Table t1 and Table t2 still be able to manipulate Table t3?

ekmett commented 11 years ago

What determines the type t3 in your signature there? it only occurs in positive position.

MetaMemoryT commented 11 years ago

Hmmm, nothing currently, t3 could be anything.

Would an instance of a typeclass be a sensible way to determine the t3 as in:

class Mergeable t1 t2 t3 | t1 t2 -> t3 where
    merge :: t1 -> t2 -> t3

innerJoin ::
    (Tabular t1
    ,Tabular t2
    ,Tabular t3
    ,Mergeable t1 t2 t3) =>
        (t1 -> t2 -> Bool) ->
    Table t1 -> Table t2 -> Table t3

I think I never need the primary keys to be the same type anymore.

Then I could use template haskell to derive for each table and joined table I want to conduct inner joins on:

ekmett commented 11 years ago

An instance seems like a pretty brutal way to make the decision. Not sure how the whole thing would come together. If you can bang something out that works, I'd be curious to see it.