lens / lens-aeson

Traversals and Prisms for Data.Aeson
MIT License
51 stars 18 forks source link

Remove AsPrimitive and Primitive #47

Closed sjshuck closed 2 years ago

sjshuck commented 2 years ago

Fixes lens/lens-aeson#26.

sjshuck commented 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.

RyanGlScott commented 2 years ago

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.

sjshuck commented 2 years ago

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.

RyanGlScott commented 2 years ago

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.

sjshuck commented 2 years ago

You're right, I only tested "42" ^? _Number, but that was merely using the AsNumber instance of a String. Thanks for clearing me up.