Coder Social home page Coder Social logo

Comments (4)

andys8 avatar andys8 commented on May 30, 2024

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.

arturopala avatar arturopala commented on May 30, 2024

from elm-monocle.

nikita-volkov avatar nikita-volkov commented on May 30, 2024

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.

andys8 avatar andys8 commented on May 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.