Friday, February 27, 2009

Finally found exponential ML type inference in real life

Today I finally hit SML/NJ exponential type inference.  (Not surprisingly, MLton has no trouble with this example.)  Using the pretty functional record update with a record of size 13, my program was not compiling.  After trying this with smaller records I found that NJ just can't compile this.  Here's the type for makeUpdate with 8 records:


val makeUpdate8 = fn
  : ('a -> 'b) *
    (((((((('c -> (((((((('c,'d) u,'e) u,'f) u,'g) u,'h) u,'i) u,'j) u,'k) u,
            'e -> (((((((('c,'d) u,'e) u,'f) u,'g) u,'h) u,'i) u,'j) u,'k) u)
             product,
           'f -> (((((((('c,'d) u,'e) u,'f) u,'g) u,'h) u,'i) u,'j) u,'k) u)
            product,
          'g -> (((((((('c,'d) u,'e) u,'f) u,'g) u,'h) u,'i) u,'j) u,'k) u)
           product,
         'h -> (((((((('c,'d) u,'e) u,'f) u,'g) u,'h) u,'i) u,'j) u,'k) u)
          product,
        'i -> (((((((('c,'d) u,'e) u,'f) u,'g) u,'h) u,'i) u,'j) u,'k) u)
         product,
       'j -> (((((((('c,'d) u,'e) u,'f) u,'g) u,'h) u,'i) u,'j) u,'k) u)
        product,
      'k -> (((((((('c,'d) u,'e) u,'f) u,'g) u,'h) u,'i) u,'j) u,'k) u)
       product
     -> 'l) * ('m -> 'n)
    -> 'm
       -> ('l *
           (((((((('o,'p) product,'q) product,'r) product,'s) product,'t)
                product,'u) product,'v) product *
            (((((((('o,'w) u,'p) u,'q) u,'r) u,'s) u,'t) u,'u) u,'v) u
            -> ((((((('o,'p) product,'q) product,'r) product,'s) product,'t)
                   product,'u) product,'v) product) * 'n,'x * 'y * 'a,'b,'z)
            Fold.t

Tuesday, February 24, 2009

Monday, February 23, 2009

Trench warfare

Fascinating discovery when reading the Wikipedia article on AxThe Evolution of Cooperation, recommended in Dacher Keltner's psychology course:

The book included two chapters comparing Axelrod's findings to surprising findings in seemingly unrelated fields. In one of these, Axelrod examined spontaneous instances of cooperation during trench warfare in World War I, often called Live and Let Live. Troops of one side would shell the other side with mortars, but would often do so on a rigid schedule, and aim for a specific point in the other side's trenches, allowing the other side to minimize casualties. The other side would reciprocate in kind. The generals on both sides were satisfied that shelling was occurring and therefore the war was progressing satisfactorily, while the men in the trenches found a way to cooperatively protect themselves.

You don't lose an inordinate percentage of heat through your head

http://www.guardian.co.uk/science/2008/dec/17/medicalresearch-humanbehaviour

Red, and perseverence

Just watched a great movie by Krzysztof Kieślowski called Red (Rouge).  Also striking is part of his biography that I read after seeing the movie.

Leaving college and working as a theatrical tailor, Kieślowski applied to the Łódź Film School, the famed Polish film school which also has Roman Polański and Andrzej Wajda among its alumni. He was rejected twice. To avoid compulsory military service during this time, he briefly became an art student, and also went on a drastic diet in an attempt to make himself medically unfit for service. After several months of successfully avoiding the draft, he was accepted to the Łódź Film School on his third attempt.

A quote:
It comes from a deep-rooted conviction that if there is anything worthwhile doing for the sake of culture, then it is touching on subject matters and situations which link people, and not those that divide people. There are too many things in the world which divide people, such as religion, politics, history, and nationalism. If culture is capable of anything, then it is finding that which unites us all. And there are so many things which unite people. It doesn't matter who you are or who I am, if your tooth aches or mine, it's still the same pain. Feelings are what link people together, because the word 'love' has the same meaning for everybody. Or 'fear', or 'suffering'. We all fear the same way and the same things. And we all love in the same way. That's why I tell about these things, because in all other things I immediately find division.

Thursday, February 19, 2009

MLton TimeLimit

Guess what this prints, and after how long:


val fastTime = Time.fromSeconds 2
val slowTime = Time.fromSeconds 6

fun fib 0 = 1
  | fib 1 = 1
  | fib n = fib (n - 1) + fib (n - 2)

fun bigfib () = fib 10000000

fun slow () = TimeLimit.timeLimit slowTime bigfib ()
    handle TimeLimit.TimeOut =>
           let in
              print "slow time out"
            ; ~1
           end

val _ = TimeLimit.timeLimit fastTime slow ()
    handle TimeLimit.TimeOut =>
           let in
              print "fast time out"
            ; ~2
           end

The rather unintuitive answer is "slow time out" after 6 seconds.
What is going on here?  I guess nesting of TimeLimits is dangerous.

Tuesday, February 10, 2009

Annoyed with SML/NJ library

- HashString.hashString "ds";
val it = 0wx6CF7 : word
- HashString.hashString "f1";
val it = 0wx6CF7 : word

Surly the default string hash should be better than this.
I'm using Tom Murphy's SHA1 implementation now.  Slower, but at least I don't have to worry about things like this.

Monday, February 09, 2009

Friday, February 06, 2009

BWV 20

The baritone aria from BWV 20 is wonderful.  I sometimes loop through random Bach cantatas at work, and some just jump out at me.  The oboe continuo in this is great.

Hacking road signs

Reposted from Bruce Schneier's blog.