Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip #37 #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

wip #37 #74

wants to merge 1 commit into from

Conversation

ryskajakub
Copy link
Contributor

So this is the draft of possible imlementation of #37.

Recap: The main problem with this issue is that changing the Column in read part of TableProperties to TableColumn, that enables having other information in the table than just the column name will possibly break type inference. Excerpt from Schema.hs:

t1 :: Table T1 T1'
t1 = Table "t1" $ p2 (T.optional "col0" Autogenerated, T.required "col1" NoIntOptions)

query :: O.Query (Column PGInt8)
query = proc () -> do
  (col1, col2) <- T.queryTable t1 -< ()
  returnA -< col1

Here, the col2 is not specified so the type inference engine don't know which instance to use. So, one needs to provide explicit type signature.

t1Query :: O.Query T1''
t1Query = T.queryTable t1

query' :: O.Query (Column PGInt8)
query' = proc () -> do
  (col1, _) <- t1Query -< ()
  returnA -< col1

Then the query' compiles.

There are some solution ideas that come to mind:

  • accept it, the user will need to provide type signatures
  • somehow run a closed type family on the read part of TableProperties, that would replace all occurences of TableColumn with Column, that can be then provided to the inferencer. Or do the same thing with macro?
  • leave the table definition as is, user needs to not modify Columns before doing schema operations.

Another obvious issue is that the type of table will change and there is one more table type for the user to specify. T1 & T' are types provided in the Table definition. T'' is a type that is used when helping the type inference.

type T1 = (Maybe (Column PGInt8), Column PGInt8)
type T1' = (TM.TableColumn PGInt8, TM.TableColumn PGInt8)
type T1'' = (Column PGInt8, Column PGInt8)

Any ideas, how to do this in an elegant way?

@tomjaguarpaw
Copy link
Owner

I have thought of something that might help with the types which is based on an idea I originally got from @bergmark. We could have an (open) type function

ColumnFromTableColumn (TableColumn a) (Column a)
ColumnFromTableColumn (a, b) = (ColumnFromTableColumn a, ColumnFromTableColumn b)
ColumnFromTableColumn (Foo a b) = Foo (ColumnFromTableColumn a) (ColumnFromTableColumn b)

which is generated automatically by makeAdaptorAndInstance. In fact I hope a single type family could be generated that works in all cases just by switching a parameter in the same way that Default is parametrized.

You might want to give this a go.

@ryskajakub
Copy link
Contributor Author

Ok, I'll go in that direction and let's see can be done.

@domenkozar
Copy link

@tomjaguarpaw reducing boilerplate and getting started would help a lot, if one could create tables out of the schema that's a good improvement. Currently the alternative is to use opaleye-gen, which has a slight unmaintainable detaste.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants