Recent Posts

Mutual Recursion in Final Encoding

Posted on May 28, 2016

Not long ago I was in­tro­duced to final en­coding of em­bedded do­main spe­cific lan­guages (ED­SLs) in Haskell thanks to a coding puzzle over at Code­Wars. While solving that puzzle I started won­dering whether it was pos­sible to de­fine mu­tu­ally re­cur­sive func­tions in an em­bedded lan­guage in final en­cod­ing. In this ar­ticle we will see that it is in­deed pos­sible and de­velop a generic and type-safe im­ple­men­ta­tion.

Read more …

Unpacking Tuples in C++14

Posted on February 28, 2016

C++11 in­tro­duced tu­ples to the C++ stan­dard li­brary. As the doc­u­men­ta­tion says they offer a fixed-size col­lec­tion of het­ero­ge­neous values. Un­for­tu­nately, tu­ples can be a little bit tricky to deal with in a generic fash­ion. The C++14 stan­dard in­tro­duced a few fea­tures that greatly re­duce the nec­es­sary boil­er­plate. In this post I will dis­cuss how to deal with tu­ples with very com­pact code.

Read more …

Jekyll Style URLs with Hakyll

Posted on January 31, 2016

Re­cently, I switched from Jekyll to Hakyll for the gen­er­a­tion of this Blog. In this ar­ticle I want to talk about Hakyll’s routing mech­a­nism and how to get it to gen­erate the same URLs as Jekyll so that all the old links to your posts keep work­ing.

If you want to follow along you can find the source code here. Step through the com­mits in the repos­i­tory to see the steps pre­sented in this ar­ticle ap­plied one after the other.

Read more …

Resource Management in Haskell

Posted on January 4, 2016

This is a post about Haskell. How­ever, I would like to point out, that I am not a pro­fes­sional Haskell pro­gram­mer. I have never had the op­por­tu­nity to use it for pro­duc­tion. How­ever, I do enjoy using Haskell for side-pro­jects. So, if you find that I made any mis­take, please leave a com­ment.

I do most of my everyday pro­gram­ming in C++ or Python and this will be re­flected in this ar­ti­cle. I will dis­cuss re­source man­age­ment in Haskell from the per­spec­tive of a C++ pro­gram­mer.

Read more …

Type Erasure with Merged Concepts

Posted on October 19, 2014

Two days ago, I watched a very in­ter­esting talk by Zach Laine: Prag­matic Type Era­sure: Solving OOP Prob­lems with an El­e­gant De­sign Pat­tern. The ques­tion that Zach Laine ad­dresses is how to pro­vide poly­mor­phic in­ter­faces while, at the same time, ad­hering to value se­man­tics. I do also rec­om­mend the fol­lowing talk by Sean Par­ent, which gives a great in­tro­duc­tion into the con­cept and the ben­e­fits of type-era­sure, and value se­man­tics: In­her­i­tance Is The Base Class of Evil

This post is mo­ti­vated by a ques­tion that came up on Reddit. Namely, how can we merge mul­tiple type-erased in­ter­faces into one single in­ter­face. A sim­ilar ques­tion is also asked in the end of the first talk: How to apply type era­sure to types with over­lap­ping in­ter­faces? The speak­er’s an­swer is to simply re­peat the common parts. I think there has to be a better way. So, in this post I am going to ex­plore how to merge type-erased in­ter­faces. But first, let’s quickly re­vise type-era­sure.

Read more …