Understanding Type classes in Scala : extending types you don’t own

Type classes are a very common pattern in Scala. My goal in this post is to demystify what they are, how they are useful, and how they are supposed to evolve in the next big iteration of Scala, currently known as Dotty. Why do we need type classes ? Type classes are a programming technique that allows you to define common behavior for multiple types. Type classes act as a kind of interface, providing a common way of interacting with multiple types, while each of those type have different concrete implementation for this interface.
Read more →

Performance of recursive functions (and when not to use them)

As powerful and appealing a tool is, it’s always better to know a little about the cost of using it before doing so. Recursion is no exception. Depending on the programming language you’re using and the problem you’re trying to solve, recursion might not be most efficient way to go. I’ll try to explain why in this article. We will cover tail call elimination, memoized functions, as well as an example of inefficcient recursive function.
Read more →

Understanding recursion

Recursion is an essential part of the functional programming tool set. It allows breaking down complex problems into a possibly indeterminate number of subproblems. It is often used as a functional alternative to loops in the imperative world, because it allows, among many other things, to loop over elements of a data structure, while preserving the immutability of your state. This post is the first one of two posts about recursion.
Read more →