1. 18

  2. 5

    I write Haskell for my research work, and I was planning on doing this year’s advent of code in it. However, since I was planning on trying to go fast (my goal was to make top 100 at least once this year), I quickly gave Haskell up when I solved a few of the 2019 problems for practice. It just felt like a lot of these problems lend themselves very well to imperative solutions, and these solutions are very hard to represent in Haskell. Good on you for sticking all the way to the end!

    You mention zippers in your post. I don’t know if you know this, but I heard that you can derive the type of a zipper by “taking the derivative” of a data structure type. For instance, suppose we represent a unit type as 1, a sum type using +, and a product type using *. To represent Either a b we can write a+b. We can write a list as l(a) = 1 + a*l(a), or (1+a)l(a) = 1 or l(a) = 1/(1+a). Taking a derivative of this – in the calculus sense! – yields (1/(1+a))^2, or l(a)^2. A zipper of a list is, indeed, two lists! Apparently, this is true in general.

    Finally, Haskell’s parser combinator approach was so intuitive to me that I implemented a version of it in my language of choice, Crystal, for one of the Advent problems.

    Thanks for sharing!

    1. 2

      Thanks for the kind words! I’m aware of the derivative approach for zippers.

      1. 2

        (Regarding the zipper derivative.) That’s incredibly awesome. Truly, math is cool. I took a category theory class a while ago but never imagined you could do stuff like this.

      2. 4

        There are no words similar to horizontal and vertical for three dimensions or more

        Sure there are! The English language is chock full of options. Mutually perpendicular adjectives, right?

        In Y-up 3D describing space,

        • X = widthwise
        • Y = heightwise
        • Z = depthwise

        If you prefer, X or Z can be “lengthwise”.

        And with any number of dimensions, you can still get away with using “first-dimension”, “tenth-dimension” et al as adjectives, much like the title of this post used “learnings” as a countable noun, or the way we’ve begun to say “gift” as a verb replacing “give”. Thank you for coming to my TED talk.