I have a nonrecord newtype which I would like to generate the lenses for:
newtype Foo = Foo (Int, String)
I would like to make a named lenses for it, currently I'm doing manually like follows:
bar :: Lans' Foo Int
bar = lens
(\(Foo (x, y)) -> x)
(\(Foo (x,y)) x' -> Foo (x', y))
I would prefer either using some TH magic here or at least more sophisticated syntax like:
bar :: Lens' Foo Int
bar = Foo <$> _1
Is it somehow possible?
You're probably looking for
Control.Lens.Wrappedto handle the newtype. You can construct aWrappedinstance via generics:and can then write: