4 ms·
A similar statement could be made about monads. Originally used to implement IO in Haskell because it’s a lazy pure functional language, they’re largely unneces
by aranchelk 4y ago
A similar statement could be made about monads. Originally used to implement IO in Haskell because it’s a lazy pure functional language, they’re largely unnecessary in strictly evaluated languages.
Monads are now of course seen by Haskellers as being very useful in many different use cases beyond the original motivation.
IO in PureScript, which I’d describe as strictly evaluated Haskell, is still implemented using monads. The biggest benefit of this (as one might expect) is forcing the separation of pure and impure code, but a cool byproduct is asynchronous IO is also implemented in a monad. Various functions are available to launch async from synchronous IO and lift synchronous functions into async. The ergonomics of mixing sync and async are better than any other language I’ve used.
So theres an interesting question: once you have dot syntax, are there reasons you’d still want lenses? I’ve come up with two.
First, it is nice to use “over” (%~) to avoid specifying a location in a data structure twice (first to read it and apply a function to the read value, second to create a new data structure with the read value replaced with the output of the function. The deeper the data structure, the bigger the benefit.
The second case is writing functions that take lenses as an input and operate generically with larger data structures without knowing where in the larger data structure the values of interest reside ahead of time.
- prionassembly 4y agoI started using monads in Python as sort of a gimmick / something to add flavor to a boring project (I was guessing in a final form we'd keep Result types and throw away most other things) but by now they're a boon to productivity and easy to read in fluent notation. Plus they're easy to implement from scratch if you're dependency-phobic (on the rather rickety selection of monad libraries out there, too).
- yccs27 4y agoWhat monad library do you use? When I tried using monads in Python a while ago it felt like Python just wasn't made for monadic programming.
- prionassembly 4y agoI use basically variations of copy-pasted code from tutorials and (I think) pymonad. I keep reimplementing things because the last API had warts. Maybe one day I'll have a library.