while true live

Musings on the fatality of infinite loops and other stuff.

Explaining the Magic

Yesterday I came across a post on the haskell reddit where somebody posted the following application of replicateM:

:m +Control.Monad
replicateM 3 "01"
-- ["000","001","010","011","100","101","110","111"]

Dark Magic

It obviously results in all three-character combinations of zeros and ones and in general, replicateM x “01” generates all x-character combinations of zeros and ones accordingly.

replicateM is a standard library function and its haddock documentation says: “replicateM n act performs the action n times, gathering the results” and its type actually is replicateM :: Monad m => Int -> m a -> m [a]. So replicateM is not a function explicitly crafted for the purpose of a “get me all x-ary combinations of my string” task, it is actually defined for all monads. Just imagine a more obvious application using the IO monad, which performs the action of printing hello 3 times and gathers the result.

replicateM 3 (putStrLn "hello")
-- hello
-- hello
-- hello
-- [(),(),()]

It is typical Haskell practice to use a function with such a general look to solve a rather special problem as our original one – to such a degree that it seems like magic to programmers with a different background. Actually, it might look like “dark” magic when you don’t grasp how/why the hell that result comes about in spite of looking at the source of replicateM, and you might start getting annoyed with Haskell altogether if that happens several times… anyway, there is no such thing as (dark) magic ;) so let’s demystify that interesting example!

Migrating a Mutating Algorithm From C to Haskell

I’ve recently stumbled on a C implementation of an algorithm computing the combinations without repetition (of a certain size k) of the first n natural numbers. So the wanted result is a list of combinations like for example 0 1 2 3 4 or 11 13 20 33 49 in the case of k=5 and n=50 (without repetition means that no number occurs twice in the same combination). As a matter of fact, I wanted to migrate that function to Haskell; so this post is about the evolution of the solution I came up with. I guess this case study is somehow kind of exemplary for the thought process which you need to undergo whenever you migrate a not-so-trivial algorithm from C to Haskell as it touches upon the topics of laziness and mutation.

Why Git Is Better Than SVN… Or Is It?

I don’t know the numbers of SVN users vs. Git users but in any case there are still many companies out there using SVN (probably more than using Git?!) The question is: Why shouldn’t they? Does Git actually provide enough benefits which are worth the hassle of migrating? If yes, how would you convince a SVN user? Have you experienced that you couldn’t comprehensively convince an SVN advocate of Git’s superiority although you’re absolutely sure of it? Or more generally: How to best convince anybody to use another technology?

This Is Not an Org-mode Tutorial

I guess it was about a year ago when I decided to give org-mode another go; I had used it before but hadn’t been able to quite wrap my head around it. This time I managed to get through the hard first difficulties so that I’m a vivid org-mode user by now… but first make clear: what is org-mode anyway and what has it to do with plain text?

Explaining Haskell RankNTypes for All

The Glasgow Haskell Compiler supports a language extension called RankNTypes which I’ve had my problems to understand. The moment I understood that it mostly refers to first-order logic universal quantification things became easier, though… but first let’s explore why we need it in a step-by-step example.

Book Catalogue

A week ago I’ve downloaded the app Book Catalogue from the Android Play store. As its name suggests it’s about creating a catalogue of your books. My family and I thought it would be handy to file our books as we easily lose track of what books we actually own and where we have stored them.

Book Catalogue makes it all possible: adding books by scanning the barcode, by ISBN, by searching author/title or by adding all information manually. Of course, every book is stored to be in exactly one bookshelf – you can create as many bookshelves as necessary and can name them as you want.

Why Blogging Matters

There is that fancy phrase “pics or it didn’t happen”. It’s just claiming evidence for a, more or less, hardly credible experience which has often to do with some sort of drug abuse. Yes, experience shows it’s sometimes cleverer to do without taking a photo, anyway, it crossed my mind that that phrase might be applicable not only to excess-like experiences but to… pretty much everything in life.

A Fresh Start

2014 has just started a month ago and I’ve painfully realized that I didn’t come up with any New Year’s resolutions at that time. There is no resolution to violate, consequently, no reason to feel bad at all – so why not start a new blog which I could then feel bad about when I post nothing for months?! Well, to be serious, that’s at least how all my blogging attempts have ended so far. I definitely don’t know if history will repeat itself again this time. Maybe this post will actually stay the only post for two months? Any bets? ;–)

Anyway, I better shortly summarize what I plan blogging about. Being a software developer, tech topics will probably dominate. Still I can’t promise not to rant about some random topic from time to time ;–) As an Emacs user I might blog about my Elisp learning progress or other stuff like the one and only org-mode. Using Octopress as my blogging engine it will be unavoidable to mention it as well, ranging from plugins and customizations to its philosophy. From time to time I’d also like talking about my journeys to Haskell wonderland and Clojure(Script) development. Or mention some Android apps? There are enough topics for sure, we’ll see if there is enough motivation to carry on blogging as well ;–)

Let’s hope the best!