purescript-contrib / purescript-profunctor-lenses

Pure profunctor lenses
MIT License
144 stars 52 forks source link

[Grate Module] Should collectOf be defined as #62

Closed syaiful6 closed 3 years ago

syaiful6 commented 7 years ago

so i played with Grate and Distributive. It look like collectOf should be defined like this:

collectOf :: forall f s t a b. Functor f => Optic (Costar f) s t a (f a) -> (b -> s) -> f b -> t
collectOf g f = zipFWithOf g id <<< map f

so i can do collectOf cotraversed, in psci it yield type:

:t collectOf cotraversed
forall t1 t5 t7 t8. Functor t5 => Distributive t8 => (t1 -> t8 t7) -> t5 t1 -> t8 (t5 t7)

which what i want. But if i apply the current implementation to cotraversed it will yied:

:t collectOf cotraversed
forall t5 t6 t7 t8. Distributive t8 => Distributive t5 => (t7 -> t5 t6) -> t8 t7 -> t5 (t8 t6)

which i believe not what we want. Notice the Distributive constraint appear both in input and output.

syaiful6 commented 7 years ago

the b type suddenly introduced on my collectOf, it look like because how this type f b -> a composed.

paf31 commented 7 years ago

Yes, I think this is right. It took me a while to see it, but the grate in collectOf is currently trying to replace the wrong functor. It should be taking the place of the Distributive funtctor, not the other one.

Could you make a PR please?

Thanks!