xkcd 1313 by simulated annealing in Clojure

Like any red-blooded American, I find regex golf fascinating. The idea, to paraphrase the comic strip, is to find a regular expression that matches all members of a group of related terms, but not any members of a different group. The hover text on the strip suggests a regex that matches all winning presidents.

Peter Norvig went to town on this, first clarifying the problem and then building an algorithm to search for the shortest solution that matches all mainstream presidential candidates who eventually won, but not such candidates who never won. (So Perot, Nader, Anderson et al don't figure …

more ...

Typecasting, part 2

Some time after my recent fiddles with IMDB, I read an interesting article about using a perceptron to classify words as parts of speech based on features that precede them in text. It's all done in python or some such sh*t, but whatever. Still very cool. Since I had all of this IMDB data accumulated in Mongo, I thought I would try to play with it, and the idea I had was to predict metacritic scores from the actors that appeared in each film. In retrospect, it's far from clear that such a prediction can be made and especialy …

more ...

Hollywood Typecasting - Adventures with typed clojure and IMDB

I am broadly sympathetic to view that scalable systems must be built with statically typed langages, for reasons outlined in this wonderful screed, and, until recently, that has made it difficult for me to recommend clojure for institutional use.

With the introduction of core.typed, that has changed. The author has says that core.typed is now production-ready, and I agree. It's not perfect, but it will find bugs in your code without breaking it or causing performance problems. It's also pretty cool, and in many ways more expressive than type declarations in "normal" statically typed languages.

That said, the …

more ...

Deriving the Y-Combinator in Clojure

At some point, everyone wakes up in the middle of the night, in a cold sweat of panic that they don't truly understand how to derive the Y-combinator. Well maybe not everyone, but at least me. (Note that I'm talking about the higher order function, not the startup incubator.) I ended up reading through quite a few web pages, all of which presupposed a slightly different background, before I finally understood. This post distills my understanding, expressed in clojure, which happens to be what I'm into now. It can now be one of the pages that someone else finds not …

more ...


Three Laws of Functor Confusion

There's a conspiracy to prevent you from understanding functors, and the here are some of the tools used to keep you in the dark:

  1. In explanations about functional programming, authors blithely use f to mean either a function or an object for which there's a functor, e.g.
  f      :: (a -> b -> c)
  fmap   :: Functor f => (d -> e) -> f d -> f e
  fmap f :: Functor f =>             f a -> f (b -> c)    -- Identify d with a, and e with (b -> c)
  1. The word functor sometimes means a mapping between categories and other times means an object in a category for which such …
more ...