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
It's probably a stretch to expect something like Shapeless to play well with Accord, but using Coproducts and HLists within your data types can lead to a more expressive domain model. I'd love to see Accord support some limited set of functionality on Coproducts/HLists. For instance, I'd really love to do something like this:
importshapeless._importcom.wix.accord._importcom.wix.accord.dsl._objectMain{
caseclassA(a: String)
caseclassB(b: String)
typeAB=A:+:B:+:CNilimplicitvalaValidator:Validator[A] =???implicitvalbValidator:Validator[B] =???implicitvalabValidator:Validator[AB] = validator[AB]{ ab =>
ab.select[A] match {
case a if a.isInstanceOf[A] => ab.select[A].get is valid[A]
}
ab.select[B] match {
case b if b.isInstanceOf[B] => ab.select[B].get is valid[B]
}
}
}
I would have expected this match statement in the abValidator to compile, but instead I just get a cryptic coproduct is not an enclosing class error from the compiler. My guess is the match statement isn't being processed properly by the macro(s) in Accord, although I must admit I haven't dug too deeply yet to verify.
The text was updated successfully, but these errors were encountered:
I would actually expect this code (convoluted though it may be :-)) to work. I'll need to do some digging to find out where the "enclosing class" error originates, but an off-the-cuff guess would be that Shapeless uses macros to derive some of the requisite type classes, and Accord doesn't handle the nested macros very well.
I can certainly believe that two separate libraries both doing macro magic might conflict with each other. I can't claim that I'm an expert in Scala macros, but it seems reasonable to suspect that perhaps something Shapeless does to transform the code has caused the validator macro to behave in unexpected ways.
For now I have just used Scala's native 'Either' type to support my use case (since I am only faced with two different options for my coproduct in question at the moment).
I don't think this is so much a bug with Accord as it is an oddity with Shapeless... hopefully whatever evolution Scala Macros take in the future will better support this sort of macro library combination scenario, although I must admit that off-hand I don't have a good idea of how one might solve such a complex problem as effectively parallel rewrites of the syntax tree.
It's probably a stretch to expect something like Shapeless to play well with Accord, but using Coproducts and HLists within your data types can lead to a more expressive domain model. I'd love to see Accord support some limited set of functionality on Coproducts/HLists. For instance, I'd really love to do something like this:
I would have expected this match statement in the abValidator to compile, but instead I just get a cryptic
coproduct is not an enclosing class
error from the compiler. My guess is the match statement isn't being processed properly by the macro(s) in Accord, although I must admit I haven't dug too deeply yet to verify.The text was updated successfully, but these errors were encountered: