Curried Thoughts 🍯 Point-Free Ramblings 🍯 Unapplied Arguments

Ziyang Liu's blog, mostly about Haskell


  • Home

  • Archives

Stage Fright Peeled Away: Writing the 'peel' Function with Template Haskell

03/10/2025
      15 mins

I was recently updating a work project’s user guide, and added a page that involves Template Haskell (TH). A reviewer noted that TH can be challenging to grasp and suggested adding pointers to learning resources. I’ve always found the trickiest part of TH to be the stage errors, which often confuse even experienced Haskell developers. I couldn’t find an existing TH tutorial that covers stage errors with the level of detail I was hoping for, so I decided to fill that gap myself.

Read more »

Understanding Space Leaks From StateT

12/13/2021
      9 mins

There are two versions of StateT in the transformers package: lazy and strict. And each version comes with two functions for updating the state: the lazy modify and the strict modify'. As long as, one might contemplate, I stick to the strict StateT and the strict modify', it should be safe and I’d need to worry no more about space leaks, right? Wrong.

Read more »

Un-obscuring a few GHC type error messages

09/01/2020
      12 mins

Generally speaking, GHC’s error messages are fairly helpful and intelligible (so long as you don’t go wild with type-level programming). But there are definitely a few common but relatively less clear ones. Some of the GHC type error messages that can potentially lead to bewilderment are discussed in this post. The GHC version I used is 8.10.2.

Read more »

How Accursed and Unutterable is accursedUnutterablePerformIO?

07/20/2020
      14 mins

Side effects break referential transparency. If you have a function f which has a pure type but performs side effects behind closed doors (e.g., f x = unsafePerformIO ...), you’d have to be careful when refactoring the code. You may want to, for instance, avoid changing f x + f x into let y = f x in y + y.

Read more »

Eat Haskell String Types for Breakfast

05/06/2020
      9 mins

This blog post summarizes, with bite-size bullet points, some knowledge on Haskell string types that I think is important to recognize when writing Haskell. The intended audience include inexperienced Haskell programmers, and experienced Haskell programmers who feel like refreshing their memory. The bullet list hopefully makes things reasonably easy to digest, and helps you eat Haskell string types for breakfast.

Read more »

A Haskell Solution to "First of Her Name" (ACM-ICPC World Finals 2019)

04/08/2020
      5 mins

Today I’m going to discuss a solution which I implemented in Haskell to a problem in ACM-ICPC World Finals 2019, titled “First of Her Name”. The solution makes use of a sorting technique called “prefix doubling” as seen in suffix array algorithms, as well as radix sort.

Read more »

Building a Friendly and Safe EDSL with IxState and TypeLits

02/29/2020
      22 mins

Haskell is a great, if not the best language for embedding DSLs in. Thanks to Haskell’s modern type system and elegant syntax, devising embedded domain-specific languages (EDSL) that are both low friction and type safe is often fairly achievable. Let’s take a simple EDSL as a running example, and evolve it in a series of steps to make it more user-friendly and safer. The main machineries involved are the indexed state monad (IxState) and some moderate type-level programming.

Read more »

A Gentle Run-through of Continuation Passing Style and Its Use Cases

01/02/2020
      21 mins

This is yet another CPS introduction post, with a focus on the use cases of CPS. This is where I find some other CPS articles to be insufficient in, for example, when I first read the CPS entry on Wikibooks, I got what CPS is but it wasn’t quite clear to me what the different ways are in which CPS can profitably be used in practice. Besides, CPS is a fairly obscure, convoluted and counter-intuitive thing, so I reckon another post that explains it is always beneficial.

Read more »

Data.List.genericLength and Space Leaks

12/05/2019
      2 mins

The codebase I regularly work with uses in many places integer types that are not Int, including Integer, Natural, Word32, Word64, etc. A number of functions in Data.List, however, only works with Int, such as length, and so there’s a lot of fromIntegrals floating around, which isn’t pretty. I was once tempted to get rid of all these fromIntegrals by using genericLength, and a coworker reviewing the PR pointed out that the doc of genericLength mentions the following:

Read more »

Fixed Points and Non-Fixed Points of Haskell Functors

08/21/2019
      16 mins

I’ve been playing with fixed points of Haskell functors lately and thought it would be useful to write down some of my thoughts, both to solidify my understanding and for future reference. If it happens to be helpful for someone else, then all the better. I guess I’ll start with Haskell’s category.

Read more »
1 2 3
Ziyang Liu

Ziyang Liu

22 posts
GitHub
© 2017 - 2025 Ziyang Liu
Powered by Jekyll
Theme - NexT.Mist