Comments (6)
Hmm, we have traverseOf
already, in Optics.Traversal
. Although it only requires a Traversal
and thus correspondingly the functor must be Applicative
, so it is not a drop in replacement, but it should work in your example?
I suppose we could have traverseOfLens
or something as a synonym for toLensVL
, but I'm not sure it is really worth adding another name.
At the very least we could explain this better in Optics.Lens
, though.
from optics.
Sorry, I should have said why traverseOf
doesn't work. I'm traversing here with Compose ((,) Tool) m
, and that is only an Applicative
if we have Monoid Tool
, which I don't have. This is because:
instance Monoid a => Applicative ((,) a)
This is why I'm looking for a lens-specific traversal, where I don't need as much as Applicative
.
from optics.
I see, sorry for not reading your example closely enough to spot that it doesn't support Applicative
.
We currently have (excluding indexed versions)
toIsoVL :: Is k An_Iso => Optic k is s t a b -> IsoVL s t a b
toPrismVL :: Is k A_Prism => Optic k is s t a b -> PrismVL s t a b
toLensVL :: Is k A_Lens => Optic k is s t a b -> LensVL s t a b
traverseOf :: (Is k A_Traversal, Applicative f) => Optic k is s t a b -> (a -> f b) -> s -> f t
atraverseOf :: (Is k An_AffineTraversal, Functor f) => Optic k is s t a b -> (forall r. r -> f r) -> (a -> f b) -> s -> f t
traverseOf_ :: (Is k A_Fold, Applicative f) => Optic' k is s a -> (a -> f r) -> s -> f ()
which feels a bit inconsistent.
So it is plausible to add (some name for)
traverseOf' :: (Is k A_Lens, Functor f) => Optic k is s t a b -> (a -> f b) -> (s -> f t)
and perhaps we might also add
toTraversalVL :: Is k A_Traversal => Optic k is s t a b -> TraversalVL s t a b
toAffineTraversalVL :: Is k An_AffineTraversal => Optic k is s t a b -> AffineTraversalVL s t a b
toFoldVL :: Is k A_Fold => Optic' k is s a -> FoldVL s a
(and indexed versions).
Of course these are somewhat redundant, but the fact they are redundant is a deep and interesting property of the van Laarhoven representation. So I can see that application code might well want "traverseOf
for a lens" without bringing the VL representation into it. And by having names for both we can more easily document the fact that e.g. traverseOf === toTraversalVL
.
To summarise: I'm convinced we should add this, I'm just not sure what to call it. Neither traverseOfLens
nor traverseOf'
feels completely satisfactory, and nor does introducing an inevitable import clash by calling it traverseOf
...
from optics.
No worries! Naming is indeed hard. My intuitive thoughts are something like traverseOneOf
, but now that I write it, it's sounds like "one of many traversals", so that's no good. traverseLens
doesn't sound so bad though - I don't think you need the Of
once you're talking about lenses.
from optics.
The naming problem comes already from how to name a class:
class Traversable t => Singleton t where
-- the member really should be verb... compare: traverse, map, ..., ...
singleton :: Functor f => (a -> f b) -> t a -> f (t b)
It only has instances for types isomorphic to (c, )
for some c
. (Thus I call it singleton - traversable with a single element).
Agda calls it Decoration
with traverseF
: https://hackage-search.serokell.io/viewfile/Agda-2.6.2.2/src/full/Agda/Utils/Functor.hs#line-56 and I couldn't (quickly) find anything else on Hackage.
from optics.
And FWIW, traverseOneOf
is particularly bad name, as there is traverse1
in the wild, which does something else what traverseOneOf
would do, even as optics
doesn't support Traversable1
things.
EDIT: In fact AffineTraversal
has similar function as well, atraverseOf
.
So we have:
traverseOf
atraverseOf
traverse1Of
(in theory)toLensVL
- and this name doesn't fit the pattern atm.
from optics.
Related Issues (20)
- Build failure in optics-extra-0.4.2 with mtl-2.3 and transformers < 0.6 HOT 8
- Drop ticks in type level constructors HOT 1
- Label optics misbehavior when defined with phantom type HOT 5
- Missing INLINE pragma on castOptic? HOT 27
- Clarify makeFieldLabels prefix requirements
- over' and iover' pretend to work with incompatible optics
- Strictify traversals?
- Improve type errors
- Support GHC 9.6 HOT 5
- Tests failing on GHC 9.4 on current Hackage release (0.4.2) HOT 3
- Unwrapping newtype should be easier than `coercedTo`. HOT 5
- Document release process
- https://gitlab.haskell.org/ghc/ghc/-/merge_requests/9411 seems to break us HOT 5
- Performance best practices regarding lens vs lensVL and Optics.TH? HOT 2
- Improve documentation on what names are generated by the various functions
- `makeFieldLabelsNoPrefix` throws error on `Network.Wai.Handler.Warp.Internal.Settings` HOT 6
- template-haskell-optics support for th-abstraction-0.6 HOT 1
- Allow dependencies bundled with GHC-9.8 HOT 3
- Versioning HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from optics.