Lenses, Folds, and Traversals

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ก.ย. 2024
  • Slides: comonad.com/has...
    This was a talk I gave at the second New York Haskell User Group Meeting (www.meetup.com/...) 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...
    A previous, more introductory talk on how to use the lenses Edward Kmett wrote for the scalaz in the Scala programming language: • Lenses: A Functional I...
    The original Applicative paper: www.soi.city.ac...
    Lots of information on Traversable: www.cs.ox.ac.uk...
    A write-up of this talk, as presented at the Bay Area Haskell Users Group: google-opensour...
    The original Keynote version of the slides are available from comonad.com/has...
    Thanks go to Johan Kiviniemi, who worked magic when it came to cleaning up the audio for this recording!

ความคิดเห็น • 40

  • @AmarrIndustrial
    @AmarrIndustrial 9 ปีที่แล้ว +83

    To read some of those slides, attendees should have brought some lenses.

    • @ekmett
      @ekmett  3 ปีที่แล้ว +4

      I've learned a little bit about managing my slide density since I gave this talk. I still tend to throw in too much code though.

  • @CaptainOfDoom
    @CaptainOfDoom 9 ปีที่แล้ว +5

    Over the course of two years, I've watched the entirety of this multiple times. I can easily USE the library, but with each time I watch this I understand more of how it works and why.

  • @SvenHeyll
    @SvenHeyll 8 ปีที่แล้ว +10

    Every now and again rewatch some parts of it I didn't get a few years ago which are now so clear, and even after several years of Haskell... I constantly learn and re-learn from this talk - more and more.
    This speaker is brilliant.
    Very dense though, I had to stop and replay some parts, but compared to a lot of other "more accessible" material better "in the long run" since there is no alternative to real understanding.
    I am still choking on "Costate Comonad Coalgebra" but one day it'll be crystal clear.

    • @jonaskoelker
      @jonaskoelker ปีที่แล้ว +1

      > I am still choking on "Costate Comonad Coalgebra"
      Here are some steps down that road: for every category, there exists a category constructed by reversing the arrows. Apply this to Haskell typeclasses to define other typeclasses.
      For example, if you have m a -> (a -> m b) -> m b, you can reverse the arrows to construct this unrelated type: m b -> (m b -> a) -> m a. Similarly "m (m a) -> m a" can be reversed into "m a -> m (m a)".
      Do that for the entire monad typeclass; the result is called a comonad. In general, "co-X" is achieved by reversing all the type arrows in X.
      Now apply this idea specifically to the state monad. That's the costate comonad.
      I'll need to review stuff to properly define a coalgebra, so for now I think of it-way too sloppily-as just "a bunch of function that work with this kind of data".
      I hope this helps a little.

    • @SvenHeyll
      @SvenHeyll ปีที่แล้ว +1

      @@jonaskoelker thanks so much!

  • @bookle5829
    @bookle5829 ปีที่แล้ว

    I'm glad you provide the slides in the description.

  • @ekmett
    @ekmett  10 ปีที่แล้ว +4

    Re: the definition of Store, the `data Store s a = Store (s -> a) s` definition given in the talk is correct. The easiest way to see is that the other definition can't even be a Functor let alone a Comonad, since `s` occurs in both positive and negative position.

  • @wlangstroth
    @wlangstroth 11 ปีที่แล้ว +4

    Somewhere around @45:00, the human oversight of subtitles drops off, and they become pretty entertaining.

  • @AlexRodriguez-gb9ez
    @AlexRodriguez-gb9ez 4 หลายเดือนก่อน

    I can't understand it, but I feel like my brain has exploded 9 times in this video...

  • @hansteam
    @hansteam 10 ปีที่แล้ว +2

    Around 57:45, dude comes up with the definition of Getter off the top of his head. Sick!

  • @TimFinnell
    @TimFinnell 8 ปีที่แล้ว +5

    the subtitles start to get amazing about 1:09:10 in 8]

    • @maninalift
      @maninalift 7 ปีที่แล้ว

      "orgasm using just the prelude" *falls off chair*

  • @wassilijstrugalski934
    @wassilijstrugalski934 2 ปีที่แล้ว +3

    "set l (view l s) s = s", really? Not "set l s (view l s) = s"(?)

  • @henrylambert6187
    @henrylambert6187 3 ปีที่แล้ว +1

    Does anybody know what the joke about SNOBOL one liners was at the very end? I can't quite make it out.

  • @JoopWilkens
    @JoopWilkens ปีที่แล้ว

    Law 1.) of the "lens" definition gives a type error, though. It's incorrectly stated.
    Correct is:
    set l s (view l s) = s

  • @Bratjuuc
    @Bratjuuc 3 ปีที่แล้ว

    Amasing job, well done!

  • @AthanClark
    @AthanClark 10 ปีที่แล้ว +2

    Do you happen to have a link to the video file? I'd love to watch + take notes offline! Thank you for this awesome addition by the way, I can see myself using the **** out of this!

    • @ekmett
      @ekmett  10 ปีที่แล้ว +1

      Sadly, no. It was rather ridiculously massive, and I didn't move it off of an old laptop.

    • @AthanClark
      @AthanClark 10 ปีที่แล้ว +1

      That's cool, I'll just rip it off youtube. Thanks anyway!

  • @ivanoleynikov7033
    @ivanoleynikov7033 2 ปีที่แล้ว

    Edward, could you please add chapters to video? It would help navigating it and going a lot!

  • @YCDPKLD
    @YCDPKLD 10 ปีที่แล้ว +26

    does anyone else find this ungodly confusing?

    • @MorganEarlJones
      @MorganEarlJones 6 ปีที่แล้ว

      The order of parameters in "s t a b" were certainly confusing enough to turn me away the first several times I tried to make a dent in lens literature. I suspect there'll be far worse hurdles to overcome before I finish this video...

    • @mikeg9b
      @mikeg9b 6 ปีที่แล้ว +1

      He should have started with a how-to-use explanation as a motivator before going into how they work.

    • @jimaylan6140
      @jimaylan6140 5 ปีที่แล้ว +2

      @@mikeg9b If you go to "hackage.haskell.org/package/lens" and scroll down to "Field Guide", it provides a great how-to-use primer

  • @DanDart
    @DanDart 19 วันที่ผ่านมา

    What happened to the subs half way through? They were great until the late 40s minutes...

    • @ekmett
      @ekmett  18 วันที่ผ่านมา

      I think my wife went and spent a few hours hand editing the first part right after the talk came out, then something prevented her from finishing the task, or from being allowed to upload the remainder.

  • @platoali
    @platoali 2 ปีที่แล้ว

    comonad weblog is offline. Any other source to the slides?

  • @bluemangroupie
    @bluemangroupie 11 ปีที่แล้ว +1

    Shouldn't the definition for `Store` @ 6:14 be `data Store s a = Store (a -> s) a`?

    • @Insipidont
      @Insipidont 6 ปีที่แล้ว +1

      The definition is correct, but if you take a closer look, when its used in the next line, its used (again, correctly) as `Store a s`. This is what was probably making you confused.
      If you replace the expressions correctly you will get the original (a -> s, a) back.

  • @zackrobat
    @zackrobat 5 ปีที่แล้ว +1

    2:13 is the beginning

  • @Crasshopperrr
    @Crasshopperrr 9 ปีที่แล้ว +1

    Anybodt know which StackOverflow answer? 5:05

  • @warwolt
    @warwolt 4 ปีที่แล้ว +1

    Very strange that the slides aren't completely in focus. Completely unintelligible

  • @LallySinghUS
    @LallySinghUS 7 ปีที่แล้ว

    Are the slides available somewhere?

    • @12xx345xx
      @12xx345xx 6 ปีที่แล้ว +1

      comonad.com/haskell/Lenses-Folds-and-Traversals-NYC.pdf
      Edit: Oh, of course they are linked in the description already >.>

  • @jollyjack5856
    @jollyjack5856 9 ปีที่แล้ว +3

    always with the poor sound quality, these Haskell videos. just can't do a decent video. half the time can't hear a thing. arrrrrrgggh.

    • @ekmett
      @ekmett  6 ปีที่แล้ว

      This was one of the first recordings at New York Haskell. They've improved drastically in the meantime.

  • @koredeaderele1666
    @koredeaderele1666 5 ปีที่แล้ว

    why does this feel like cheating