frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Lens: Lenses, Folds and Traversals

https://hackage.haskell.org/package/lens
51•hyperbrainer•3d ago

Comments

moomin•4h ago
Let’s just say that if you wanted to understand lenses, this is not where you should start; and if you wanted to move to more advanced scenarios, I wouldn’t start here either.
xtoilette•4h ago
where would you start?
neanderzander•4h ago
I found this accessible:

https://academy.fpblock.com/haskell/tutorial/lens/

wk_end•2h ago
Assuming you've got experience with Javascript, read the "Motivation" section on the monocle-ts website:

https://gcanti.github.io/monocle-ts/

raluk•20m ago
https://blog.jle.im/entry/lenses-products-prisms-sums.html
ohdeargodno•4h ago
A first good step is getting rid of Haskell's obscure and impenetrable syntax, and checking implementations that would be more readable.

Kotlin's Arrow library hits a good middle ground between FP wizardry and readability, and their documentation on lenses are understandable for the average person: https://arrow-kt.io/learn/immutable-data/lens/ / https://arrow-kt.io/learn/immutable-data/intro/

epgui•49m ago
> Haskell's obscure and impenetrable syntax

Uhhh... Haskell syntax is simpler than python's or javascript's. It's neither obscure nor impenetrable, but it sounds like it's different than what you're used to.

smegma2•3h ago
Agreed, I think this tutorial is good: https://hackage.haskell.org/package/lens-tutorial-1.0.5/docs...
kccqzy•4h ago
My biggest piece of advice for people using lenses is to ditch all the operators. Things like ^. or ^.. or ^? or ^@.. or even <<|>~ are all real operators. Yet they look like line noise. Nobody fully remembers them anyways. Just ditch all operators. Use named functions. The function toListOf is immediately clear what it's doing (that it takes a structure and a fold to convert to a list) but ^.. is not.

In general I avoid all custom operators and only use operators that are in packages preinstalled by the compiler (basically just base and containers).

kqr•3h ago
I agree strongly with this and take it one step further: I avoid the infix backticks that turn functions `into` operators.

But I'm not a hardliner. I do use backticks sometimes when building joins with Esqueleto and I do use a limited set of lens operators, like ^. and sometimes the %= variants if the situation calls for it.

amelius•3h ago
Maybe a text-editor should allow the user to look at source code through different "lenses" (pun intended) and show the meanings of symbols whenever the user wants to see them.
ashton314•1h ago
Emacs (of course) has `prettify-symbols-mode` which lets you describe symbols (eg lambda) and replacement characters (eg λ); the effect is purely in the display system—the underlying buffer does not get modified.
chowells•1h ago
I strongly recommend using the lens operators. They are uniformly named such that you can trivially identify their behavior based on their lexical construction, and using them reduces mental parsing overhead significantly.

For the former assertion: ^. means "get a single result". ^.. means "get multiple results". ^? means "get zero or one result". ^@.. means "get multiple results, along with their indices". <<|>~ means "modify a value by combining the target with the |> operator from Snoc, then return a tuple of the old target value and the full structure including the combined value". There is a tiny language in the pattern of operator names, and it's worth the 3 minutes of work it takes to learn it.

And as a reward for learning it, you get to write expressions with far fewer parentheses. This is a massive win. Parenthesized expressions introduce a miserable minigame during reading, where you have to properly match each paren to its correct partner keeping a mental stack to handle nesting. By contrast, the lens operators give you the far simpler mental parsing task of separating the optic, the input, and the operation on the input. There's no nesting involved. The process is a simple visual scan that doesn't require keeping a mental stack. It's a lot easier to quickly read and comprehend.

About the only thing you lose is the ability to easily read code out loud. I don't limit myself to thinking in sounds, but I guess for some people it's important to communicate code out loud. For those kinds of pedagogical purposes, I guess it's ok to pass on the operators. But for code I'm going to work with over a long period of time I'd much rather have the readability advantages of the operators.

kccqzy•5m ago
Having fewer parentheses is not a win, it makes more things implicit and forces everyone to remember operator precedence. In my opinion operator precedence is never worth remembering other than plus minus multiply and divide.

I find heavily parenthesized expressions easy to read, just because I tend to break them into multiple lines and the indentation serves as a guide. Don't put too many of them on a single line.

aranchelk•2m ago
I disagree. There are many operators that you’ll never use but if you memorize (^.), (.~), and (%~), you’re pretty much set for a lot of real-world software development.

Per Kmett’s original talk/video on the subject, I can confirm my brain shifted pretty quickly to look at them like OOP field accessors. And for the three above, the mnemonics are effective:

“^.” is like an upside down “v” for view.

“.~” looks like a backwards “s” for setters.

“~%” has an tilde so it’s a type of setter and “%” has a circle over a circle, so it’s over.

I’ll also add that my experience in recent versions of PureScript things get even nicer: visible type application lets you define record accessors on the fly like:

foo ^. ln@“bar” <<< ln@“baz”

“.” Is unfortunately a restricted character and is not the composition operator like Haskell, but I alias “<<<“ with “..”

The pretty obvious question with the above is: why don’t you just write “foo.bar.baz”. In my case I use a framework that uses passed lenses for IoC, but I think “%~” is always nicer and less repetitive than the built-in alternative.

haskman•2h ago
If you are looking for a more accessible introduction to lenses, this guide to optics in PureScript is great (and PureScript is basically Haskell). https://thomashoneyman.com/articles/practical-profunctor-len...
eigenspace•1h ago
Julia actually has a very nice implementation of lenses in the Accessors.jl package: https://juliaobjects.github.io/Accessors.jl/dev/

I find it to be a lot more comprehensible and transparent than the Haskell version.

Mini NASes marry NVMe to Intel's efficient chip

https://www.jeffgeerling.com/blog/2025/mini-nases-marry-nvme-intels-efficient-chip
156•ingve•3h ago•68 comments

LLMs caused drastic vocabulary shift in biomedical publications

https://www.science.org/doi/10.1126/sciadv.adt3813
26•em3rgent0rdr•40m ago•3 comments

EverQuest

https://www.filfre.net/2025/07/everquest/
63•dmazin•2h ago•19 comments

Why I left my tech job to work on chronic pain

https://sailhealth.substack.com/p/why-i-left-my-tech-job-to-work-on
212•glasscannon•6h ago•134 comments

How to Incapacitate Google Tag Manager and Why You Should (2022)

https://backlit.neocities.org/incapacitate-google-tag-manager
11•fsflover•46m ago•3 comments

Compression Dictionary Transport

https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Compression_dictionary_transport
44•todsacerdoti•3h ago•4 comments

Kepler.gl

https://kepler.gl/
77•9woc•5h ago•9 comments

Show HN: I AI-coded a tower defense game and documented the whole process

https://github.com/maciej-trebacz/tower-of-time-game
141•M4v3R•6h ago•85 comments

Larry (cat)

https://en.wikipedia.org/wiki/Larry_(cat)
184•dcminter•9h ago•43 comments

UpCodes (YC S17) is hiring a Head of Ops to automate construction compliance

https://up.codes/careers?utm_source=HN
1•Old_Thrashbarg•1h ago

Writing a Game Boy Emulator in OCaml

https://linoscope.github.io/writing-a-game-boy-emulator-in-ocaml/
185•ibobev•9h ago•29 comments

Bcachefs may be headed out of the kernel

https://lwn.net/Articles/1027289/
52•ksec•5h ago•42 comments

Lens: Lenses, Folds and Traversals

https://hackage.haskell.org/package/lens
51•hyperbrainer•3d ago•17 comments

Can Large Language Models Play Text Games Well?

https://arxiv.org/abs/2304.02868
44•willvarfar•7h ago•27 comments

Show HN: BunkerWeb – the open-source and cloud-native WAF

https://docs.bunkerweb.io/latest/
66•bnkty•7h ago•25 comments

Eight dormant Satoshi-era Bitcoin wallets reactivated after 14 yrs

https://twitter.com/WatcherGuru/status/1941167512491864554
11•amrrs•16m ago•1 comments

Is an Intel N100 or N150 a better value than a Raspberry Pi?

https://www.jeffgeerling.com/blog/2025/intel-n100-better-value-raspberry-pi
191•transpute•6h ago•175 comments

``Free as Air, Free as Water, Free as Knowledge'' (1992)

http://bactra.org/Sterling/Free_as_the_Air_Free_as_Water_Free_as_Knowledge.html
7•whoopdedo•3d ago•0 comments

In a milestone for Manhattan, a pair of coyotes has made Central Park their home

https://www.smithsonianmag.com/science-nature/in-a-milestone-for-manhattan-a-pair-of-coyotes-has-made-central-park-their-home-180986892/
82•sohkamyung•3d ago•71 comments

Wind Knitting Factory

https://www.merelkarhof.nl/work/wind-knitting-factory
195•bschne•22h ago•54 comments

ChatGPT creates phisher's paradise by serving the wrong URLs for major companies

https://www.theregister.com/2025/07/03/ai_phishing_websites/
9•josephcsible•27m ago•0 comments

A Rust-TypeScript integration

https://github.com/beeeeep54/rust-typescript
40•wreedtyt•7h ago•43 comments

Zig breaking change – initial Writergate

https://github.com/ziglang/zig/pull/24329
166•Retro_Dev•14h ago•178 comments

Rust and WASM for Form Validation

https://sebastian.lauwe.rs/blog/rust-wasm-form-validation/
32•slau•6h ago•15 comments

Show HN: A cross-platform terminal emulator written in Java

https://github.com/sebkur/forceterm
44•sebkur•3d ago•5 comments

Killer whales groom each other with pieces of kelp

https://www.science.org/content/article/killer-whales-groom-each-other-pieces-kelp
69•noleary•3d ago•42 comments

Show HN: Fast Thermodynamic Calculations in Python

https://dlr-institute-of-future-fuels.github.io/gaspype/
42•Saloc•7h ago•8 comments

DRM Panic QR code generator

https://rust-for-linux.com/drm-panic-qr-code-generator
61•weinzierl•11h ago•26 comments

Gremllm

https://github.com/awwaiid/gremllm
7•andreabergia•2h ago•3 comments

Serving 200M requests per day with a CGI-bin

https://jacob.gold/posts/serving-200-million-requests-with-cgi-bin/
109•feep•5h ago•47 comments