ekmett / lens

Lenses, Folds, and Traversals - Join us on web.libera.chat #haskell-lens
http://lens.github.io/
Other
2.03k stars 274 forks source link

Is the type of review too specific? #902

Closed yairchu closed 3 years ago

yairchu commented 4 years ago

https://github.com/ekmett/lens/commit/e51df36d2f40513b7cc015d74b1477b46a24bf4c made review's type more specific.

It was a problem for me when trying to do:

I ran into this when experimenting with this:

vprism ::
    (Choice p, VerboseApplicative e f) =>
    e -> APrism s t a b -> Optic p f s t a b
vprism e p =
    dimap (matching p)
    (either (vpure e) (fmap (review p))) .
    right'

Simply re-implementing the old review made the above work:

review' :: MonadReader b m => APrism s t a b -> m t
review' p = asks (runIdentity . unTagged . clonePrism p . Tagged . Identity)

Why was review made specific? Is that to assist type inference?

Note: I have a vague memory of having asked this before but I couldn't find such an issue. I apologise if that's indeed the case and I'm being redundant.

phadej commented 4 years ago

Why was review made specific? Is that to assist type inference?

Yes.

We have getting for getters, but no reviewing to make Review type "more polymorphic". The only problem with adding that is the name, but I guess reviewing will be fine.

yairchu commented 4 years ago

I attempted created a reviewing and wound up with this:

reviewing ::
    (Choice p, Bifunctor p, Functor f, Settable f) =>
    APrism s t a b -> Optic' p f t b
reviewing p =
    bimap f (fmap f)
    where
        f = runIdentity . unTagged . clonePrism p . Tagged . Identity

Will it suffice?

(I'm aware that the type is not as general as getting's, but I haven't succeeded in making an equivalent one nor am I knowledgeable enough to tell if it can be done)