tiempo - A library for time units/intervals in Haskell

TL;DR: A library to specify time units easily

It has come to my attention that sometimes as a library developer, there is no easy way to specify time in asynchronous functions. One particular example comes to mind:

threadDelay :: Int -> IO ()

One thing I find disturbing about this signature, is that just by its types I can’t tell what this function is expecting, is it milliseconds, seconds, minutes? Most of Haskell standard library functions that work with time in one way or another use microseconds as the standard unit; sadly the standard library for some reason doesn’t provide an alias for Int so that the signature could be the documentation.

Another problem that I normally have is: what happens if I’m developing a library that works with time, that uses an internal API that works in millisecond units? should I use the same Int and expect milliseconds, or should I expect microseconds and do the transformations myself inside the function. Is this the right way to go?

After playing with distributed-process-platform (a.k.a Cloud Haskell’s OTP), one thing that got my attention was the fact that they used a type for different time units, replicating their effort into a way less ambitious library I came up with this:

import Tiempo

main :: IO ()
main = do
  threadDelay (microSeconds 3000)
  threadDelay (milliSeconds 500)
  threadDelay (seconds 3)
  threadDelay (minutes 1)
  threadDelay (hours 1)

Providing time intervals this way looks more appealing to me, I can specify the units myself on the function (not common knowledge required). If you are a library developer and need to have one specific time unit, you can get the right unit easily using a transformation function.

-- threadDelay is already implemented by Tiempo, but I'm  
-- providing the definition here for the sake of completeness

import Tiempo
import qualified Control.Concurrent as Concurrent

threadDelay :: TimeInterval -> IO () 
threadDelay interval = Concurrent.threadDelay (toMicroSeconds interval)

Independently of the unit specified by the client code, I can get the unit I require to satisfy the spec of a lower API.

Hopefully you will find this library as useful as I do, and kudos for the devs from Cloud Haskell to provide this little yet awesome idea.

Gonzo enjoying the afternoon sun


Recently we have been working on a project that use the Reactive Extensions library (rxjs) on the front-end and Conduit for handling event and IO streams in Haskell. In practice, working with rxjs is similar to using Conduits/Iteratees/Pipes in Haskell. Of the many benefits [pdf] of rxjs,…


:) @romanandreg and I just implemented animated replay of event-sourced UI test fixtures http://rxtest.dentalle.com/#fixture:separate_post_metals::animate vs http://rxtest.dentalle.com/#fixture:separate_post_metals which just jumps to the end state and highlights the last change.

The fixtures…

Great Work

Last week I implemented an emacs plugin called golden-ratio.el to resize the window I’m editiing in, the size to which it is resized follows the golden ratio measures, hence the name, I’m leaving this image here to use it later in github/forums.


Somebodies, por Gotye. Un remix de videos amateurs covers de Somebody That I Used To Know.

The power of collaborative work, is just amazing…

Installing emacs24 in precise pangoling

This is specially useful in vagrant machines

  1. Install utility to add apt sources easily:

    sudo apt-get install python-software-properties
  2. Add sources that contains emacs24

    sudo add-apt-repository ppa:cassou/emacs
  3. Update the apt source list and install emacs24-nox (for emacs without X)

    sudo apt-get update; sudo apt-get install emacs24-nox


“Udacity isn’t concerned with students who fall short. Its creators are busy trying to help those who ace every triple-gold-star problem and never miss a quiz—the young men in Lahore, Beirut, and Caracas who haunt Internet cafes and spend hours engaging in jargony repartee about elegant solutions on the Udacity message board. These are the people that Udacity hopes to help recruit to talent-hungry dot-coms like Google and Amazon”

Funny how they mention Caracas as one of the places with people with low resources…

From this blogpost

Installing virtualbox guest additions

Whenever I upgrade the version of my virtualbox env, I always run through the annoying warning given by vagrant, saying that the virtual machine doesn’t have a matching version to the virtualbox-guest-additions.

In order to solve this issue, I always follow the steps given in this blogpost.

I re-post this steps over here for my personal records…