Hlint obliged me by telling me exactly how to simplify the code using idiomatic Haskell. I must confess that I abused hlint by throwing really bad, hacky code at it. hlint exposes this rewrite rule, letting you know that you can simplify your code. Haskell is smart enough to rewrite this code as the single pass version: map (f3. (map f1) list takes a list of values and makes three passes over the list, applying a function each time. The easiest place to see Haskell’s compiler magic is in the hlint plugin, which actually exposes some of these compiler passes to you.įor example, (map f3). The tools I used for this exercise were VSCode, HLS, hlint, and stack. There are many things to learn here, not just ivory tower programming language theory. Having said that, your experience with Haskell may surprise you even if you don’t think of yourself as a math person. Most people don’t think in math, which is probably why Haskell will never be mainstream. The way this works is that Haskell forces you to write in a mathematically pure way that the compiler can use to make mathematically guaranteed transformations. The Glasgow Haskell Compiler (GHC) is the closest thing I have seen to the mythical “sufficiently smart compiler”. I didn’t find my way out of that rabbit hole and ran out of vacation days. More on this below…)ĭay 16 was parsers so I ended up exploring the rabbit hole of parsers, for which Haskell is the undisputed #1 language. (You think I’m goofing about the PhD thesis… I’m not. I initially misdiagnosed day 15 as a memoization problem, so I also read the “PhD thesis” on memoization in Haskell before realizing I’d goofed. I didn’t finish AoC, but the questions I completed covered a diverse array of programming concepts: iterators (day 1), fold/reduce (day 2, 3), state machines (day 4), multidimensional arrays (day 5, 9, 11, 12), math/logic (day 6, 7, 8, 13, 14), flood fill (day 9), stacks (day 10), BFS/DFS (day 12), string munging (day 14), Djikstra’s (day 15), parsers/binary protocols (day 16). For each problem, I tried to do it “correctly” in Haskell, rather than hacking my way through the problem. Over the 2021 Christmas season, I worked through problems 1-15 of the Advent of Code in Haskell. Obligatory disclaimer: all opinions are mine and not of my employer
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |