Comments (4)
Interesting. I didn't know it doesn't exist in Haskell. It does in Scala and TypeScript.
For me, not coming from Haskell, it looks like they serve a different purpose and have different type signatures. Prism
converts structures, Optional
sets nested values.
https://mobile.twitter.com/puffnfresh/status/654862731548446720
https://stackoverflow.com/questions/33725534/are-monocles-optionals-the-same-as-partial-lenses
I'm not arguing for one or the other. Instead I'm curious how it's done in Haskell and what the advantages of removing Optional
are and how its usages will be replaced.
from elm-monocle.
from elm-monocle.
For me, not coming from Haskell, it looks like they serve a different purpose and have different type signatures. Prism converts structures, Optional sets nested values.
Actually, I've screwed up and you've helped me realise it. Thanks!
Prism
does the same thing in Haskell as both in this library and Scala. Haskell does in fact lack Optional
: see the abstractions hierarchy (from the "lens" library). It however does have a thing that achieves the same purpose as Optional
, only in a more general way: it's Traversal
and the difference is that it lets you point at multiple locations.
This made me google for traversals in Scala's Monocle, and I've discovered that the library has both Traversal
and Optional
: https://julien-truffaut.github.io/Monocle/optics/traversal.html. So while I still am not sold on the usefulness of Optional
, since we don't have Traversal
here yet, it's better that we have that at least. I'll close the issue.
from elm-monocle.
Thanks @nikita-volkov, I learned something.
I am wondering how traversals (#24) should be implemented and if they're useful for something else than List
. They could work for Array
, Maybe
and other container's though. I would like to play around with them. The API will probably look like those in other languages without type classes.
from elm-monocle.
Related Issues (12)
- Error on install HOT 3
- Consider adding some extremely common optionals? HOT 2
- Examples for Common.dict and Common.array do not seem to work HOT 2
- Implementation specifics question HOT 2
- Is the example for `Prism` correct? HOT 11
- Infix operator alias for Lens.compose HOT 6
- Optional for list too HOT 5
- Elm v0.19 HOT 2
- Crazy idea: methods for pipeline-style composition (to replace operators) HOT 10
- Traversal HOT 15
- Example in README doesn't work, no operator "=>" 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 elm-monocle.