Skip to content

Conversation

@tomjaguarpaw
Copy link
Owner

@tomjaguarpaw tomjaguarpaw commented Sep 5, 2021

This looks super useful. I'm not sure why we didn't come up with this before!

Any thoughts? (Particularly @ocharles and @duairc). The same would work for EitherFields.

@tomjaguarpaw tomjaguarpaw marked this pull request as draft September 5, 2021 09:31
@ocharles
Copy link
Collaborator

ocharles commented Sep 5, 2021

Oh, this is pretty cool. I have a little prototype of something similar but wilder - I made Query have Cont like capabilities, then

x <- leftJoin ...
... x

has leftJoin capture the continuation, and then invoke the continuation with x = Nothing and x = Just x' and union the results. This means I can write:

leftJoin ... >>= \case
  Nothing -> _
  Just x -> _ x

and it Just Works.

I'm a bit nervous of this though, because obviously it incurs some pretty significant SQL. Your suggestion here looks to be basically the same idea, but rather than doing it at the Query level, you're doing it more at the expression level. It's also much more opt-in than my approach.

I'm not sure about the type class and the DSL, I think matchMaybe alone is fine. With -XBlockArguments, you get:

foo <- leftJoin ...
matchMaybe foo \case
  Nothing -> bar
  Just x -> baz x

Which looks perfectly reasonable to me.

Something else I've been considering oddly just got published to the Arxiv, which is to use pattern synonyms. https://arxiv.org/abs/2108.13114 is the paper in question, but the idea is essentially to have:

pattern Just_
pattern Nothing_

and to have these transparently look at the tag.

So there's a whole bunch of stuff here, all with merit. I dunno which to pick!

@tomjaguarpaw
Copy link
Owner Author

I'm not sure about the type class and the DSL, I think matchMaybe alone is fine.

Yeah, that's fair.

Something else I've been considering oddly just got published to the Arxiv

Interesting! The Reddit discussion prompted me to consider this but I haven't actually read the paper yet.

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