Open treeowl opened 7 years ago
Another option, that feels like it may possibly fit better with lens
(rather than a profunctor lens library) is
lensical :: Functor f => (s -> a) -> (s -> b -> t) -> p a (f b) -> p s (f t)
But I have no sense of whether this generalization is useful.
Such methods also add corresponding alternatives to Pastro
. Simplest:
data Pasta p s t where
Pasta :: (s -> a) -> (s -> b -> t) -> p a b -> Pasta p s t
instance Strong (Pasta p) where
lensE getter setter (Pasta sa sbt p) =
Pasta (sa . getter) (\s b1 -> setter s (sbt (getter s) b1)) p
pastaToPastro :: Pasta p s t -> Pastro p s t
pastaToPastro (Pasta sa sbt p) =
Pastro (\(b,bt) -> bt b) p (\s -> (sa s, sbt s))
pastroToPasta :: Pastro p s t -> Pasta p s t
pastroToPasta (Pastro f p g) =
Pasta (fst . g) (\s y -> f (y, snd (g s))) p
I was reading about profunctor-based lenses (specifically, http://oleg.fi/gists/posts/2017-03-31-compiling-lenses.html) and it pointed out that there's a method that could be added to
Strong
:Indeed, I realized (and I'm sure I'm not the first to do so) that this one method offers defaults for
dimap
,first'
, andsecond'
:Since tuples can be a bit expensive, I wonder if adding a method like this could be helpful.
Dually,
Choice
supports an all-powerful method: