My Programming Escapades
Andraz Bajt
Lazy unary numbers
We are used to encoding numbers on computers in binary. Binary is the “simplest” base that yields logarithmic length though it may not be optimal. But can we do simpler? How about unary? Unary is often used with Turing machines where we don't care for efficiency and I will assume this same stance. Let's forget about efficiency and explore what can unary numbers do that binary can't. Specifically lazy unary numbers as otherwise the systems are equivalent.
Cheap tagged types in Scala
Sometimes you want to distinguish between different types that have the same underlying representation. For example both UserId and ProductId could be represented by Long. The usual solution is to introduce wrappers in order to make the distinction safe. case class UserId(id: Long) case class ProductId(id: Long) But this introduces runtime overhead of boxing and unboxing over and over which may add up in some cases. Luckily Scala 2.10 introduced value classes.
Approaches to designing a Haskell API
Recently I've been thinking about the design of programming interfaces, especially in Haskell. But don't let the title misguide you; this is not supposed to be a tutorial or a guide but simply an showcase of different styles. Feel free to tell me I'm wrong or missed something. The problem Let's say we are writing an interface to RESTful web service. Our goal is to create type safe functions and descriptive models but all in all easy to use.
Static linking with GHC on ArchLinux
There are many reasons why to prefer dynamic linking to static but I'll not go through them. Sometimes you just want static linking, period. In my case it was to show that Go‘s static executables without dependencies are not something special and other languages can do it as good as well - Haskell included. My compiler of choice is GHC and I'm running ArchLinux. More on why this is important later.
Coroutines for free
Motivation My first run-in with coroutines was with Python's generators. def ints(): i = 0 while True: yield i i += 1 This is a function that never returns. Instead it runs in an infinite loop over all natural numbers. But it yields every number. This means it actually stops and “returns” the number to the caller but is available for more execution. Kind-of like implementing an Iterator but the control flow is reversed.
Practical Future[Option[A]] in Scala
Motivation In real world concurrent code you often come across the Future[Option[A]] type(where A is usually some concrete type). And then you need to compose these things. This is not straightforward in Scala. If you've done some Haskell just import scalaz._ and you can skip the rest of this article. Scalaz library defines a monad typeclass(and many others) that formally specifies what it means to be a monad(not “has a flatMap-ish thingy”).
Comparing Haskell Web Frameworks
Intro Lately I got sucked into Haskell. When I first saw it it looked like it might be a bit impractical for real-life projects but this prejudice faded away slowly. Now I'm at the point where I have an idea for a web application and I'd like to do it in Haskell. After a quick search I found many frameworks and libraries that I might use. So I decided to do some exploration and implement a bunch of stuff with different technologies.
Product and sum types (Go and Haskell)
Let's take a look at Go-language functions. They let you return more than one result. Like in func foo(n int) (int, int) { return n+1, n+2 } This function foo returns two numbers. But does it really? Pairs(and tuples in general) aren't a first class citizen in Go. Yes you can return them from function and you can even return a result of a function that returns the same signature as you but then you must immediately bind each result to separate variable.
Hello there. I think I'm gonna resurrect this blog as I feel like writing again. I kinda have a general dislike for PHP and don't like Wordpress. I tried mucking about with Github Pages, but I'm not a fan of Jekyll either. And then I forgot about this. Haskell A few weeks ago I rediscovered Haskell. I tried learning it once before but gave up. And insisted in Scala. This time I believe I got past the hardest part of the learning curve.
Virtual machine in C++
This is not a tutorial. This post is a flashback I had today. It might be a bit fiction as my memory about events tends to be fuzzy at times. But I promise it at least resembles the real story. I was in elementary school and just found out about programming and was learning about c++. After reading “C++ na kolenih” by Goran Bervar I was empowered by knowledge and tried to do all sorts of projects.