Wednesday, February 25, 2009

FSharp.IsRecord

Eyebrows raised while looking at Microsoft.FSharp.Reflection.FSharpType. Quote:
member IsRecord : typ:Type * ?bindingFlags:BindingFlags -> bool
Return true if the typ is a representation of an F# record type
Trying it out:
> FSharpType.IsRecord(typeof<int*int>);;
val it : bool = true
Why would tuples be records, really?

Record Calculi. John C. Mitchell, Atsushi Ohori

Roman Cheplyaka pointed me to a good book (Foundations for Programming Languages) by John C. Mitchell. As a side effect, my eye was caught by the author's mention of object-oriented language foundations and record calculi. Record calculi? Really? A few more googles, yes indeed, there are ways to mathematically formalize operations on labeled records, providing for object-oriented languages what lambda calculus provides for functional. First hit on Google Scholar is a 1995 paper by Atsushi Ohori, "Polymorphic record calculus and its compilation"; Ohori in fact has plenty of interesting and publicly available papers. Apparently one use case of this lore is polymorphic type inference for record types in the ML family.

Tuesday, February 24, 2009

Random sampling of views. MS SQL

I (heart) MS SQL. To take a fair random sample of a view or a table, you need a fair amount of SQL acrobatics. Not only that, you'd want to index the views if you do not want to wait forever for your sample. Indexed views come at a cost, last but not least of explaining to your client that the databasse schema needs to be changed. Please, RDBMSs of all kind, die. It is 2009, not 1989.

Which Scheme?

PLT/mzscheme has been my number one choice. Reasonably fast (like naively written Haskell), with a very friendly community, runs on a VM, cross-platform, incredibly easy to install librares (PlaneT), fully dynamic FFI to C, does R6RS, has its own very nice extensions. I just could not figure out how to do ODBC - is it still supported? Now I am looking for alternatives for the compiled use case, for example for producing small binaries, or plugins to C systems. Bigloo and Chicken seem attractive. It is hard to choose, both seem very good. Please, no Common Lisp. UPDATE: I went for Chicken and I am really impressed! C integration is tight, binaries are very small (shared runtime), user libraries are as easy to install as Linux packages, it is easy to compile shared libraries. Bigloo must have its advantages too but for now I am sticking to Chicken.

GMAIL Outage?

Is it just me, or is GMAIL not working? 502 Server Error.. UPDATE: No, about 20 people a second were Twitting about it. The world sure likes to complain!

Saturday, February 21, 2009

hdaemonize - for enunuchs demons in haskell

Writing little programs that stay live and do work, should not be hard, right? Well, on the UNIX platform it is not quite so! Just search the net for "LINUX Daemon Writing HOWTO.." hdaemonize collects all the cruft daemons do into a library, so that you can do this:

import Control.Concurrent
import System.Posix.Daemonize

main = daemonize $ \log ->
       do flag <- newEmptyMVar 
          let stop   = do log "STOPPING"
                          putMVar flag ()
          let loop i = do threadDelay $ 10^6
                          writeFile "/tmp/counter" $ show i
                          loop $ i + 1
          let start  = do log "STARTING UP"
                          forkIO $ loop 0
                          takeMVar flag
          let reload = log "RELOAD SIGNAL CAUGHT"
          return $ Program start stop reload

This little program writes into /tmp/counter the number of seconds since its start, and reports its events to daemons.log; it is also ready to be deployed to /etc/init.d or /etc/rc.d; started by root, it will drop priviledges to the daemon user, or, if you name the program 'foo' and user foo exists, to user foo. Far from being a UNIX guru, I am almost certain that I did some mistakes in the library, so I release it open-soure and welcome corrections. hdaemonize home: http://github.com/toyvo/hdaemonize/tree/master inspiration for the code: http://sneakymustard.com/2008/12/11/haskell-daemons

Tuesday, February 17, 2009

Giving up on self-hosting

I gave up on self hosting and host the blog with Google. Reasons? To speed up the long-awaited death of PHP, make sure I don't lose the data, make it easier for people to comment. What I regret with moving to Blogspot is the ability to transform the text. Code and formula snippets are bound to get messed up. But thankfully, for publishing code and formulas there is a Gitit copy available.