Bit Vector in JavaScript

A bit vector (also known as bit set or bit array) is a set data structure which uses only 1 bit per element. It answers the question is X in the set?. The main advantage is memory efficiency and speed, as the memory is allocated in a single continuous block, making it very cache friendly (unlike some tree based data structures), and requiring only a few bitwise operations to access/modify elements in the set.

Read More →

Visualizing TensorFlow Graphs in Jupyter Notebooks

TensorFlow operations form a computation graph. And while for small examples you might be able to look at the code and immediately see what is going on, larger computation graphs might not be so obvious. Visualizing the graph can help both in diagnosing issues with the computation itself, but also in understanding how certain operations in TensorFlow work and how are things put together.

Read More →

Fibonacci Numbers

We'll take a look at different ways of calculating fibonacci numbers in JavaScript. Starting from simple recursive implementation, followed by dynamic programming and an iterative approach.

Read More →

Thoughts on OS X Yosemite, Arch Linux and xmonad

I’ve been using OS X as my main machine for quite a while now, mainly because I got into Ruby development, and having a Mac is just the thing you do when you write Ruby (at least that’s what I thought back then.) One of the main reasons why I really fell in love with the Mac is that things just work. There is no hassle in setting up your drivers, or connecting a printer, or getting your favorite app to work.

Read More →

Parsing CSS with Parsec

This article is a small introduction to Parsec, the Haskell parser combinator library for Haskell. We’ll use it to parse simple CSS file such as the following. .container h1 { color: rgba(255, 0, 0, 0.9); font-size: 24px; } First we need to figure out our data structure which will represent the syntax tree. Since this is just an introduction, we’ll go easy and ignore features like media queries. In order to create the structure we need to figure out how to name things.

Read More →

Lens Tutorial - Stab & Traversal (Part 2)

In the first article in the series about lenses, we’ve looked at the motivation behind the lens library, and we also derived the basic type of Lens s a. In this article we’ll go deeper and explain the reasoning beheind the more generic Lens s t a b type. We’ll also take a look at how we can get a multi focus lens using a Traversal. Just to reiterate, here’s how looks the type we derived in the previous article.

Read More →

Foldable and Traversable

Before we can get into the more advanced topics on Lenses, it is important to really understand both Foldable and Traversable, which is the motivation behind this article. Let’s begin with Foldable. Foldable represents structures which can be folded. What does that mean? Here are a few examples: Calculating the sum of a list. Calculating the product of a list. Folding a tree to get a maximum value. We can describe a fold as taking a structure and reducing it to a single result.

Read More →

Building Monad Transformers - Part 1

In this article we'll focus on building our own monad transformers. We'll start out with an example code and improve it by building a simple wrapper over IO (Maybe a). The following example is really simple, but I'm sure you can imagine doing something similar in your own application. The findById method is there just to simulate a database query that might not find a result.

Read More →

Mutable State in Haskell

Haskell is a purely functional language, which means there are no side-effects and all variables are immutable. But as you probably know this isn’t completely true. All variables are indeed immutable, but there are ways to construct mutable references where we can change what the reference points to. Without side effects we wouldn’t be able to do much, which is why Haskell gives us the IO monad. In a similar manner we have many ways to achieve mutable state in Haskell, let’s take a look at them:

Read More →

Lens Tutorial - Introduction (part 1)

This article is the first in the upcoming series that aims to explain the Haskell’s lens library and the ideas behind it in an approachable way. Don’t worry if you’re new to Haskell, the only prerequisites here should be understanding of the Functor type class, and understanding how records and algebraic data types work in Haskell. We won’t be using the lens library in this article yet. The API we’ll develop will be exactly the same, but for the sake of learning I’ll try to show you how everything works and why it works by re-implementing it from scratch.

Read More →