Toxic Elephant

Don't bury it in your back yard!

Tab Sweep: Monads

Posted by matijs 29/01/2010 at 12h47

Learning about monads is hard, and there seems to be no magic pill. Probably one reason is that they have several different uses. Many articles focus on one of those uses, making it hard to get the whole picture. On the other hand, articles that try to directly explain what monads are leave the reader wandering what they're good for. Some links.

  • Brent Yorgey argues that any shortcut by focusing on a particular metaphor (e.g., monads are like burritos) will not work.
  • Mark Dominus argues why monads are indeed like burritos.
  • [Monads as Containers][cont] fits in nicely by abstracting away from burritos (or space suits) to containers. It goes on to talk about how this relates to IO and other uses for monads. I'm still working on reading through this article.
  • sigfpe starts from the other end, showing how certain needs could automatically lead to monads. I haven't finished that one either, but so far it's been very insightful.
  • I also found The Continuation Monad in Clojure very insightful. Again, it focuses more in the use and implementation, rather than abstract theory. I'm not yet sure whether the insights I myself got from it are actually correct. More on that later, perhaps.

Tags no comments no trackbacks

How to Get Apache and Typo Page Caching to Play Nice

Posted by matijs 13/12/2009 at 18h58

The Problem

You have been running a Typo blog [since 2005][since], but you still can’t quite get your Apache configuration right. In particular, you still get the occasional

Not found: http://www.matijs.net/blog/2005/07.html/24/from-bryar-to-typo

Note the weird 07.html part.

Tags , , no comments no trackbacks

Photos from Tokyo

Posted by matijs 29/11/2009 at 10h56

We recently returned from a trip to visit Naoko’s parents in Tokyo. We took lots of pictures. Here are some of them.

Bowl of Ramen with bean sprouts and a slice of pork

A nice bowl of ramen with creamy broth, crunchy bean sprouts and delicious soft pork. I love ramen.

Bride in traditional Japanese wedding kimono

A wedding at Meiji Shrine. We went to the shrine during Shichi-Go-San, so there were lots of little girls and a couple of little boys all dressed up in kimono. Our daughter, having just turned three, was one of them.

Close-up of red autumn leaves of the Japanses maple

Of course, it is the season of beautiful autumn leaves. It is actually quite hard to capture the beauty of these maples.

Female Nephila clavata, seen from below

This picture of a female Nephila clavata spider was taken near Chichibu. This one measured about 6 or 7 cm diameter (including legs). One of the locals told us that they let the spiders fight each other for entertainment. Of the locals, that is.

Pile of small raw octopus

A pile of small raw octopus at the famous Tsukiji fish market, which I finally managed to visit.

Tags no comments no trackbacks

RSpec Still Sucks

Posted by matijs 25/10/2009 at 11h25

I run rake spec and get:

Test::Unit::AssertionFailedError in 'XmlController test_bad_format'
Expected response to be a <:missing>, but was <301>
/var/lib/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/test_case.rb:114:in `clean_backtrace'
./spec/controllers/xml_controller_spec.rb:152:in `test_bad_format'

So, things fail in xml_controller_spec, right? So, I run:

./script/spec spec/controllers/xml_controller_spec.rb

And I get this:

27 examples, 0 failures

WTF??

Yes, this turns out to be due to the fact that the spec in question was in its original form as migrated from Test::Unit. But that’s not really an excuse: Either Test::Unit style tests work in RSpec, or they don’t. They shouldn’t work some of the time. Now I suddenly can’t trust any of the Test::Unit style tests in Typo anymore: Are they passing because the code works, or because of some mystical internal RSpec magic?

I am mass-replacing lines of def test_bla_bla by it "test_bla_bla" do right now.

Tags no comments no trackbacks

Very Simple Nautilus Plugin to Show Deletion Date

Posted by matijs 18/05/2009 at 09h14

Gnome’s file manager, Nautilus, does not natively support showing the deletion date for trashed items. This has annoyed me, and others, for a very long time.

Long story short, I created a very simple implementation in Python as a Nautilus plugin. You can find it in its github repository.

This solution has one drawback to : Nautilus plugins can only add string columns, so to make it sort right the date is not in a very user-friendly format. I like to think of it more as proof-of-concept.

What’s next? Nautilus has hard-coded support for sorting by each of its possible date columns. It would be nice to make that more generic so as to allow adding arbitrary date columns, or columns with the sort key and user-visible text separated.

Tags no comments no trackbacks

Some Links

Posted by matijs 26/03/2009 at 12h11

These can all be seen as being about art: Art of programming, video, sound.

Pascal Costanza’s Highly Opinionated Guide to Lisp. A real guide:

Something like “Lisp for experienced programmers”

Just what I needed. Convinced me that Common Lisp will be the next programming language I learn.

Datamoshing: from _why’s article (with examples), to a practical guide (itself datamoshed). The technique uses accidental properties of current video compression: The compression partially separates motion from color, so we can combine the color from one still image with completely unrelated motion from another clip. Perhaps this can be cleaned up by:

  • Fully separationg motion and color information (the compression algorithms only do partial separation)
  • Allowing partial recombining of the color, creating the possibility of a ‘fade-in’ of the ‘correct’ color, or other effects.
  • All this supported by your favorite non-linear editor program, of course.

This would give more control, but less interesting unexpected artifacts. It’s a trade-off.

And finally: sCrAmBlEd?HaCkZ!, automatically recreates one audio track (music, mainly), by glueing together similar-sounding pieces from another track (or set of tracks). Very impressive. Be sure to watch the explanatory video.

Tags no comments no trackbacks

The Arc Challenge

Posted by matijs 17/02/2008 at 21h14

Hm, so Arc is here, and Paul Graham gives the Arc challenge. The answer in Arc is short indeed. First, let’s see an answer in Rails (loading a framework is allowed according to the challenge), with said_controller.rb:

class SaidController < ApplicationController
def index; end
def click; session[:it] = params[‘what’]; end
def show; end
end

and some templates, for the first page, index.html.erb:

<% form_tag ‘/said/click’ do >
<
= text_field_tag ‘what’ >
<
= submit_tag >
<
end %>

second page, click.html.erb:

<%= link_to ‘click here’, {:action => ’show’} %>

third page, show.html.erb:

You said <%= session[:it] %>

The Rails answer may be a little longer (although by how much is hard to say due to the different syntax — is end a token?), but it not a case of the same but longer.

First, the Rails version is in temporal order, the Arc version is not. Perhaps there’s a way of reading the Arc version that makes this order natural, but right now, it looks confusing.

But the most striking difference is that it is based on a completely different philosophy of how web applications should be developed. The Arc answer is great if you want a web application based on continuations. The Rails answer is what you would use if you want to use REST.

I’m definitely in the REST camp, which makes this example meaningless as a demonstration of Arc. It shows me that Arc can be used to write a short program that does something I don’t want to do.

The ultimate question of course is whether brevity (in terms of number of tokens, not characters) is the single best metric for language power.

Update: Someone wrote a Ruby version that is about as short as the Arc version, uses the same paradigm, and is in temporal order:

def said
aform(input(“foo”), submit) {
w_link(“click here”) {
“you said: #{arg :foo}”}}
end

Tags 2 comments no trackbacks

Aaargh!

Posted by matijs 14/02/2008 at 21h35

I’m upset. I’m so upset that I was originally going to call this entry “Fuck you, Python”. Now, I realize that’s not a very nice thing to say, and actually, Python can’t really help it anyway. Except by not existing1.

Why, why, why must every other new language created these days have significant indenting? You see a new language, like Cobra, you read the overview of features, and you go, cool, great runtime performance, static and dynamic typing, and contracts, too. So you browse on to the hello world example, and boom! the absence of end-of-block tokens hits you in the face like an iron fist.

Now, in Python’s case you can tell from the reasoning2 and the implementation that somebody actually thought this through, but Cobra has the following rationale for using this method of block structuring:

Cobra uses indentation to denote code structure since adept programmers do this anyway in languages that don’t even require it (C#, Java, C++, etc.)

Wow. I’m going to make a language that uses the comma-space token to separate function arguments, since adept programmers put a space after the comma in languages that don’t even require it.

Look, if you use indenting for block structure because you like Python, just say so already.

Oh wait, there’s more:

In Cobra, one INDENT is accomplished by one TAB or four SPACES.

Huh? Because adept programmers indent four characters anyway even in languages that don’t require it? Because adept programmers use one tab per four spaces anyway even in editors that don’t require it?

Sheesh.

I feel much calmer now.

1 See how reasonable I am. I’m not actually calling for the non-existance of Python.

2 I don’t agree with that reasoning either, but at least it’s, you know, reasonable.

Tags 3 comments no trackbacks

Hello New Year!

Posted by matijs 23/01/2008 at 06h36

It’s a new year! Time for more resolutions. I can’t believe that’s actually two years ago.

Yes, my blog has been neglected, but not for want of anything to write about. Oh, there are so many things I have an opinion about. But always, it’s the question, is my opinion interesting, new, well informed, etc? And can I write something sizable about it? Not conductive to writing every monday (recently replaced by sunday, but I bet you hadn’t guessed). Maybe I should try less hard to be reasonable.

Oh yeah, e-mail is getting better, mainly thanks to the Inbox Zero articles.

What I really want to be doing: I still don’t really know, but let’s look at what I might blog about:

  • Size is the Enemy, leading to the issue of abstractions in programming languages.
  • 80/20, or the problem of getting your average Java/.NET programmer to really learn and use new things (e.g., new methods of abstraction).
  • Lots of new languages are popping up, all running on some VM or other (e.g., Scala, Nemerle, Boo). Where’s the development in regular compiled languages?

This surely points in some direction, but some weighted average will have to be taken to find out what that direction is.

I did manage to quit the job that was definitely going in the wrong direction, so there’s a plus.

Oh, you wanted new resolutions? Hm, let’s do some:

  • Uncluttered house
  • Learn Japanese
  • Finish more software so it’s releaseable

Tags , , no comments no trackbacks

The Beauty of Git

Posted by matijs 10/11/2007 at 18h57

After my struggles with svk, working with git is a breath of fresh air. It has great support for branching and merging, and putting even the smallest of throwaway projects under version control becomes as simple as:

git init

Gone are the days of the “oh i’ll just make ten copies of this script here because setting up a repository takes too long” style of version control.

Tags no comments no trackbacks