Closed sjshuck closed 2 years ago
I marked the containing convo resolved, but I want to echo my comment here for any follow-up:
Re-added [class constraint
AsNumber t => AsValue t
]. However, to me this reads as "everything I might want to discern as a Value, I might also want to discern as a Scientific", which I don't really understand from a practical perspective. Not that I have to.
However, to me this reads as "everything I might want to discern as a Value, I might also want to discern as a Scientific", which I don't really understand from a practical perspective.
I guess I was thinking about it from a convenience perspective. That is, if you have an AsValue t
constraint and want to get a Maybe Scientific
out of it, then the superclass allows you to write x ^? _Number
directly instead of the slightly less direct x ^? _Value._Number
. A minor convenience, for sure, but a convenience nonetheless.
You can do that even without the class constraint. All the constraint seems to do is require any user who wants to make their own AsValue
instance to first also make it an AsNumber
instance.
You can do that even without the class constraint.
Just to be sure we're talking about the same code, I have this scenario in mind:
f :: AsValue t => t -> Maybe Scientific
f x = x ^? _Number
That won't typecheck unless AsNumber
is a superclass of AsValue
, unless I'm missing something.
You're right, I only tested "42" ^? _Number
, but that was merely using the AsNumber
instance of a String
. Thanks for clearing me up.
Fixes lens/lens-aeson#26.