I can see the end (almost)
I was really tempted to skip this week’s newsletter, cause that would have meant that I could spend less time in front of my screen typing away. After almost a straight week of preparing for presentations, and writing some truly cursed LaTeX, I’m pretty ready to just not write anything for a while.
Alas, I’ve been writing one of these every week since the first week of September, so I won’t stop now. That said, I don’t think I’ll write anything too fancy. I’ll give some updates on my projects and talk a bit about what I’ve been doing in my “spare” time.
Right before I typed this up, our group finished our final report for CPSC 547. I’m pretty happy that this course is coming to an end (not that I didn’t enjoy it), because it means that I can check one more course off my list before I can officially start my winter break. If there’s one new thing I learned about LaTeX this week, it’s that figure placement on a 2-column template can literally make one want to jump off a building. In the end, I wrote some truly cursed hacks that eventually forced the layout of our figures and text to be something serviceable. Once we submit our report tomorrow, we’ll be done with the course and I can finally move back to our course project for CPSC 513, which should be a bit more heavy on the programming.
Recently I’ve been trying my hand at Haskell again. The last time I played around with it was in back in ‘17 or ‘18. At that time, I knew less than I know now about functional programming so I was pleasantly surprised when I realized that more of the concepts made sense to me. I could dare say that I finally understood the “joke” definition of a monad:
“a monad is just a monoid in the category of endofunctors, what’s the big deal?”
I’ll definitely be fun at parties when I whip that line out. I was pleasantly surprised when I realized my time with Scala had actually translated somewhat into Haskell. Here are some of the things that I could map over directly
Option[T]
is just aMaybe A
.flatMap
is equivalent to a>>==
- a
for-comp
is kinda like ado-return
I really enjoyed how terse Haskell’s syntax is, I felt like I could abstract away a lot of the boilerplate I had to write with Scala and still end up with some expressive code. There’s also the upside of finally learning a language in the ML-dialect, which is something I’ve been meaning to do for a while.
Something that really made me smile was how something I learned in 110 over nearly 5 years ago almost directly translated into Haskell code. Take for example the following definition of a fold
function in Racket and Haskell (I’ll probably miss some parens in Racket)
;; (X Y -> Y) Y (listof X) -> Y (define (fold f b lox) (local [(define (rec lox acc) (match lox [`() acc] [(cons x rest) (rec rest (f x acc))]))] (rec lox b)))
fold :: (a -> b -> b) -> b -> [a] -> b fold f b xs = let g [] acc = acc g (y:ys) acc = g ys (f y acc) in g xs b
I probably wrote some really disgusting, unidiomatic Haskell, but it really drives home the point that the things we learned in 110 are pretty fundamental. Even the signature (which is a comment in the dynamically-typed Racket), is expressed the same way (albeit as a curried version) in Haskell.
Nerding out over this was pretty fun. All my deadlines should be over by the 22nd, so hopefully then I’ll have more time to write something a bit more coherent. Until then, stay safe!