Skip to content
0:00 / 0:00

#lenses#lenslibrary#traversals

Lenses, Folds, and Traversals

Edward Kmett

2.7K subscribers • 3 videos on Hallway

YouTube
  • Recommended by 5 people: 3 on Hacker News, 1 on Lobsters and 1 curated list.
  • A classic. People kept recommending it from 2013 to 2016.
  • Presented by Edward Kmett, creator of the Haskell lens library

Advanced. Deep dive for people who know the field.

54K views13 years ago5 recommendations

Programming languagesSoftware designFunctional programmingHaskellDesign patterns

Edward Kmett explains how to build highly composable combinators for accessing and modifying complex data structures using the lens library.

Slides: comonad.com/haskell/Lenses-Folds-and-Traversals-NYC.pdf This was a talk I gave at the second New York Haskell User Group Meeting (meetup.com/NY-Haskell/) on the new lens library, which provides a highly composable toolbox for accessing and modifying multiple parts of data structures. Starting with building blocks such as fmap and (.), we build up combinators suitable for working with a wide array of data structures. These generalize the notions you already know how to use into a form that is easier to compose and simultaneously allow them to be used for monomorphic containers such as Data.Text. All without compromising on your ability to reason about them using laws! Finally, once I've built up some foundations, I do a bit of a deep dive, exploring consequences of this design. In particular we discuss the efficient generic programming programming framework exported by lens, and type-safe Traversal-based zippers. Familiarity with the Applicative and Traversable classes from the Haskell base libraries will be helpful (links provided below), but a basic understanding of the concepts get introduced as I go along. Useful (but not mandatory) references: The lens library and documentation: hackage.haskell.org/package/lens A previous, more introductory talk on how to use the lenses Edward Kmett wrote for the scalaz in the Scala programming language: youtube.com/watch?v=efv0SQNde5Q The original Applicative paper: soi.city.ac.uk/~ross/papers/Applicative.pdf Lots of information on Traversable: cs.ox.ac.uk/jeremy.gibbons/publications/iterator.pdf A write-up of this talk, as presented at the Bay Area Haskell Users Group: google-opensource.blogspot.com/2012/10/lenses-folds-and-trav… The original Keynote version of the slides are available from comonad.com/haskell/Lenses-Folds-and-Traversals-NYC.key Thanks go to Johan Kiviniemi, who worked magic when it came to cleaning up the audio for this recording!

Why it's here

5 people recommend this

What people say. Recommended as a mind-blowing and comprehensive guide to understanding lenses and functional references in Haskell.

Moments people linked to

mijoharason Hacker News • Recommends

On “How I Start: Haskell”

I found this talk by edward kmett incredibly helpful0. I kept rewatching parts of it bit by bit until I managed to absorb it all (there is a lot of information for a beginner) but I found it hugely helpful and mind-blowingly powerful. 0 link to this video

apyon Lobsters • Recommends

Lenses, Folds, and Traversals

programming-talkscurated list on GitHubRecommends

Under “Haskell”

Lenses, Folds, and Traversals 01:54:46 by **Edward Kmett** (2012)

jerfon Hacker News • Recommends

On “Why is the C++ STL so heavily based on templates?”

…ress language is also doing some work here. A sample of the interesting sort of algorithm work that you can do when you think this way: link Edit: See also the Typeclassopedia: link And if you're really interested and want to take it hardcore, Edward Kmett's video on his lens library walks through how you can derive it with this sort of logic: link to this video…

dllthomason Hacker News • Recommends

On “Letter to a Young Haskell Enthusiast”

"The best forms of language advocacy probably involve showing the great things you've done with a language and forgetting about comparisons to the competition." Great things the parent has done with the language: link to this video

u/haskellgr8in r/haskell • Mentions

Explaining abstract Haskell stuff to mere mortals - and can mere mortals be professional Haskell devs? For example, only after watching this talk by S. P. Jones could I understand (a part of) E. Kmett's lens library. Contrast Jones's talk with this totally incomprehensible talk by E. Kmett :) Kmett and others like him will continue developing their great stuff and explaining it to other geniuses. That's fine. All I'm saying is it would be nice if more people made all this knowledge accessible to mere mortals. I have a question to you full-time professional Haskell devs: Do you think such "mere mortals" can be professional Haskell devs or should all professional Haskell devs be able to,…

u/Competitive_Ad2539in r/haskell • Mentions

Any good material about how to think about and use profunctors? I've met them in profunctor optics tutorials, but I can't understand how to think about them. Sure, they are just "double" functors, that are contravariant on the first type argument and covariant on the second one, but how the hell should I understand why Strong profunctors form lenses, and Choice ones form prisms, e.t.c.? Even this video, where there are only UpStar profunctors disguised as regular functions, was hard to wrap my head around.

u/ElCthuluIncognitoin r/haskell • Mentions

Anybody have a copy of the "Lenses, Folds, and Traversals" slides PDF? I've been following along Edward Kmett's presentation "Lenses, Folds, and Traversals", and there was a PDF document with the slides available that I was putting to good use to 'decipher' the presentation and learn a lot from it. It used to be available from the link in the video description but it's now a dead link. Does anyone have a copy or know of an alternative source for the PDF laying around?

u/fosskersin r/haskell • Mentions

On “fmap fmap fmap fmap fmap fmap fmap fmap”

Reminds me of Ed's lens video.

u/haskmanin r/haskell • Mentions

On “From Lenses to Yoneda Embedding”

This is great! It's a subject that is quite fascinating and that I am only recently getting familiar with. I started writing a Lens tutorial (https://github.com/ajnsit/haskell-tutorials/blob/master/lenses-from-scratch.md) after watching Edward's talk (link to this video which follows a similar course. I hope you won't mind if I borrow some bits from your writeup (with attribution of course).

u/crvdgcin r/haskell • Mentions

On “Deriving not-so-complex types”

It reminds me of Edward Kmett's talk on Lenses. It begins with `(.)` `(.).(.)` `(.).(.).(.)` and `fmap` `fmap . fmap` `fmap . fmap . fmap` , which is pretty intimidating at first glance.

u/penguinlandin r/haskell • Mentions

On “A Little Lens Starter Tutorial - School of Haskell”

I infer from your username that you wrote this. Could you go back and finish changing your example from using `age` and `lifetime` to `location`? Things were going great up until then. Thank you for posting this! I hadn't heard of lenses before yesterday, so I started going through the link to this video and slides linked from the Hackage page. After 2 hours, I was 45 minutes into the video and had only grokked a third of it. Your introduction is much more easily understood.

u/mishachin r/haskell • Mentions

On “Any advanced / complete Lens reference?”

link to this video very good video.

u/crvdgcin r/haskell • Mentions

On “Point-free”

I might write a blog later. This has nothing particular to do with `sequence` and `fmap`. The goal is: we want to define a function `mapM` in terms of two functions `sequence` and `fmap`. For this composition to work, we want the next two arguments to be passed to `fmap`, then forward the result to `sequence`. As is shown in the first panel: `mapM f xs = sequence (fmap f xs)`. If there's only one argument to be passed to `fmap` before forwarding the result, then the composition is easy, we just use a single `.`. However, here we want to wait for two arguments. This is a rather common scenario. To simplify the discussion, let's forget what `sequence`, `fmap`, and `mapM` actually do, and let…
5View on Reddit

u/stevelyin r/haskell • Mentions

On “School of Haskell—Basic Lensing”

For something more along the lines of what you're suggesting there's this talk by Edward Kmett. It didn't do me much good in understanding lenses, but it's very in-depth.

u/arianvpin r/haskell • Mentions

On “The Haskell Cast: Episode 1 - Edward Kmett on Lenses”

Related: link to this video I didn't understand half he said though. Maybe I should watch this again when I'm sober and got a GHCi REPL at hand.