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

A variant of select that doesn't require QBaseScope #652

Open
enobayram opened this issue Dec 16, 2022 · 2 comments
Open

A variant of select that doesn't require QBaseScope #652

enobayram opened this issue Dec 16, 2022 · 2 comments

Comments

@enobayram
Copy link

Wouldn't it be completely safe to have a variant of the select function with the following signature:

select' :: forall s be db res. 
  (BeamSqlBackend be, HasQBuilder be, Projectible be res) => 
  Q be db s res -> 
  SqlSelect be (QExprToIdentity res)

I.e. one that doesn't insist on having QBaseScope. I know this is an odd thing to want, but I find myself writing higher order beam utilities that involve passing query fragments around, and they play better with type inference when the types are as monomorphic as possible and sometimes that requires me to select a Q be db (QNested something) res. If I understand the purpose of QNested correctly, it's not safe to cast a Q be db (QNested QBaseScope) res to a Q be db QBaseScope res in general, but it should be safe to select a Q be db (QNested QBaseScope) res, right? If my assumption is correct, having that select variant would enable some advanced use cases for me.

I know I could just copy-paste the implementation of select and give it the type I want, but I want to confirm here that it is indeed a safe thing to do.

@tathougies
Copy link
Collaborator

QBaseScope et al were put in place because of limitations of the Haskell type system at the time. It's likely we can get rid of this. In fact, we should probably rethink the entire scoping system in light of new GHC features, and be willing to break compatibility.

@enobayram
Copy link
Author

That sounds terrific. IME, the s parameter is the biggest friction to higher order programming with beam. Still doable, but it requires careful thought.So I'd say removing that friction is definitely worth a major version.

If my understanding is correct, the purpose of the s parameter is to make sure that bindings from one scope can't be used in a nested scope where, due to the underlying SQL semantics, those bindings shouldn't be visible. So, I'm curious, what are other ways you can enforce these boundaries without the s parameter?

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

No branches or pull requests

3 participants