-
Notifications
You must be signed in to change notification settings - Fork 115
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
Derive a type class only for wrapper types (unary product types) #278
Conversation
I can see that this works, but it does seem like it might be the first step down the wrong path, just due to the amount of additional and repetitive code required. But I had an idea about this, and I think it might be possible to introduce a couple of macros, completely orthogonal to Magnolia, which materialize typeclass evidence for a particular type if that type conforms to a certain criterion. For example, the macro would materialize evidence of the type Then, in the Doobie code, it should then be possible to provide different implicit derivations for the case where the |
Here's a rough version of the macro:
|
ok yeah, that's a reasonably path going forward for me, thank you for the idea! :) The only negative I see with that is it might lead to quite a few more macro expansions, but we could live with that. So a follow-up idea to this PR, what do you think about tagging @magnolia.constraints.minMembers(1)
@magnolia.constraints.maxMembers(1)
def combine(...) In my head that looks like a flexible way of expressing this and similar constraints which shouldn't complicate the implementation much. Would you be interested in something like that instead? |
…ill only be derived for a type if that type has a given range of number of members (so far, though it could be extended)
I implemented my last proposal as it was pretty easy to do, and pushed it to this same branch. Let's see what you think about it @propensive . I'll update the PR description if you think this is more viable. On the plus side it leads to less code explosion now, and it'll be extensible if we discover further needs in the future. It also plays well I think with magnolias good error messages. I think this is a real need actually, lately I have touched 4 type classes with specific needs in this direction
Also just to have said that I think my immediate problem in doobie is solved by your macro suggestion, but I'd prefer this solution, if nothing else to expand fewer macros. If you judge it's not general enough to live in magnolia that's also fine, I'll leave it at this attempt :) |
Hi again @propensive
We need to reintroduce this functionality into doobie after tpolecat/doobie#1343 .
So this is a first stab at it. If we continue down this path we'll pretty quickly see an explosion of needed types, so it's not necessarily a good path. The whole thing is really a whole lot of ceremony around some critically placed
if
s.I thought about introducing some kind of type-level set of requirements (for instance "must be case class", "must have more/less than N members", and so on) which the macro could query. This, however, was the easiest way forward.
Looking forward to hearing what you think