Using lenses

Niklas Haas haskell
Thu Oct 3 04:34:31 UTC 2013


I use lenses for almost all of my code, now, in particular the ?lens?
library due to the tons of syntactic conveniences it provides.

The main thing I tend to use ?lens? for is actually folds (or
traversals), not lenses themselves. I like to construct big folds,
restrict them with filters or prisms, take them apart with stuff
like ?splittingOn? or ?chunking?, glue them together with combining
functions like ?failing? or ?mappend?, and finally read them out with
things like ?preview?, ?foldrOf?, ?has? or ?elemOf?.

My other big use case for lenses is combining them with StateT to write
pretty darn imperative-looking code, which is the ?records? or ?lenses?
approach most people are probably more familiar with.




More information about the Libraries mailing list