Not long ago I was introduced to final encoding of embedded domain specific languages (EDSLs) in Haskell thanks to a coding puzzle over at CodeWars. While solving that puzzle I started wondering whether it was possible to define mutually recursive functions in an embedded language in final encoding. In this article we will see that it is indeed possible and develop a generic and type-safe implementation.
Read more …
C++11 introduced tuples to the C++ standard library. As the documentation says they offer a fixed-size collection of heterogeneous values. Unfortunately, tuples can be a little bit tricky to deal with in a generic fashion. The C++14 standard introduced a few features that greatly reduce the necessary boilerplate. In this post I will discuss how to deal with tuples with very compact code.
Read more …
Recently, I switched from Jekyll to Hakyll for the generation of this Blog. In this article I want to talk about Hakyll’s routing mechanism and how to get it to generate the same URLs as Jekyll so that all the old links to your posts keep working.
If you want to follow along you can find the source code here. Step through the commits in the repository to see the steps presented in this article applied one after the other.
Read more …
This is a post about Haskell. However, I would like to point out, that I am not a professional Haskell programmer. I have never had the opportunity to use it for production. However, I do enjoy using Haskell for side-projects. So, if you find that I made any mistake, please leave a comment.
I do most of my everyday programming in C++ or Python and this will be reflected in this article. I will discuss resource management in Haskell from the perspective of a C++ programmer.
Read more …
Two days ago, I watched a very interesting talk by Zach Laine: Pragmatic Type Erasure: Solving OOP Problems with an Elegant Design Pattern. The question that Zach Laine addresses is how to provide polymorphic interfaces while, at the same time, adhering to value semantics. I do also recommend the following talk by Sean Parent, which gives a great introduction into the concept and the benefits of type-erasure, and value semantics: Inheritance Is The Base Class of Evil
This post is motivated by a question that came up on Reddit. Namely, how can we merge multiple type-erased interfaces into one single interface. A similar question is also asked in the end of the first talk: How to apply type erasure to types with overlapping interfaces? The speaker’s answer is to simply repeat the common parts. I think there has to be a better way. So, in this post I am going to explore how to merge type-erased interfaces. But first, let’s quickly revise type-erasure.
Read more …