Abusing the writer monad

I was just thinking, it turns out that if you have a complex list of parameters (i.e, essentially a 2D array), you don’t need a list interface. Instead, you can abuse the writer monad to allow extremely clean deployment via a do block.

However, the problem is that monoidal append on lists and vectors is O(n), and Seq IIRC has poor inherent performance characteristics.

If, say, you want to take arguments via a custom writer monad, what would be the way to do it?

This isn’t something specific to writer monad, but if you are looking for a list-like data type with cheap append operation, you can use difference lists.

1 Like

I can’t imagine this being a problem in any case where the syntax matters, i.e. you’re writing it out by hand.

2 Likes

When in doubt, benchmark :wink:

5 Likes