You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While writing #57, it occurred to me that it might be possible to do something general to "override" the behavior of existing methods on types. I think one can write a generic ForwardingFunctor that allows you to declare something like
Then, when encountering a method call in a path, quicklens could first first call Context. inferImplicitValue(ForwardingFunctor[tpe.typeConstructor, tpe.typeArg, {method signature}]), where method signature is a structural type that matches the signature of method. If nothing is found, it can fallback to copies. Obviously the previous is not valid code but I hope you get my meaning.
This would allow client code to override the behavior of any existing method on any existing class without writing new macro code, so for example you could override Array.apply to act like at, and you could also allow people to call defs defined on case classes. I'm not entirely sure this will all work out, I'm still learning what the limits of macros are, and there's definitely some subtleties around higher-kinded types and mismatches in type parameters. Just a thought, would you be interested if I could work it out?
I'd happily take this on if you think this feature would be useful.
The text was updated successfully, but these errors were encountered:
adampauls
changed the title
[Feature request, speculative]
[Feature request, speculative] Allow arbitrary method "forwarding"
Mar 10, 2020
Right, yes, I'm aware of that. IIUC though, the nice thing here is that the structural types would be compile-time only, just there to provide a way to get a handle on the implicit. No reflection would actually be called at runtime. I'm not sure if there's away to actually @compileTimeOnly those types, I can look into it.
While writing #57, it occurred to me that it might be possible to do something general to "override" the behavior of existing methods on types. I think one can write a generic ForwardingFunctor that allows you to declare something like
Then, when encountering a method call in a path, quicklens could first first call
Context. inferImplicitValue(ForwardingFunctor[tpe.typeConstructor, tpe.typeArg, {method signature}])
, wheremethod signature
is a structural type that matches the signature ofmethod
. If nothing is found, it can fallback to copies. Obviously the previous is not valid code but I hope you get my meaning.This would allow client code to override the behavior of any existing method on any existing class without writing new macro code, so for example you could override
Array.apply
to act likeat
, and you could also allow people to call defs defined on case classes. I'm not entirely sure this will all work out, I'm still learning what the limits of macros are, and there's definitely some subtleties around higher-kinded types and mismatches in type parameters. Just a thought, would you be interested if I could work it out?I'd happily take this on if you think this feature would be useful.
The text was updated successfully, but these errors were encountered: