I'm having a hard time reading the types in the Control.Lens.Wrapped module and I'm not finding much else written about it or the newtype library it is apparently based on. In particular I am wondering what sorts of things I can do while remaining in the newtype wrapper. For instance let's say I have two lists that are in a Data.Monoid.Sum wrapper. Is there some way I can easily ++ the lists and get back a new value still in a Sum wrapper? I would want a function that, monomorphically, looks something like this:
canIdoThis :: ([a] -> [a] -> [a]) -> Sum [a] -> Sum [a] -> Sum [a]
so that I could do something like
canIdoThis (++) (Sum [1,2]) (Sum [3,4])
and get Sum [1,2,3,4]. (Of course, canIdoThis would also work on Product [a], etc.)
Any other tips or just a general write up of all the goodness one could do with Control.Lens.Wrapped is appreciated very much.
Doesn't use Wrapped, but:
import Data.Coercible
canIdoThis :: ([a] -> [a] -> [a]) -> Sum [a] -> Sum [a] -> Sum [a]
canIdoThis = coerce
Are you sure these should be wrapped in Sum? No instance Num [a] by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With