Monthly Archives: March 2007

It’s over between us…

Back to blogger.com. LaTeX support can’t make up for the fact that it’s impossible to display Haskell source code on wordpress (it strips out backslahes from inside PREformatted text). And wordpress.com makes silent edits to your HTML source (eg. discarding line breaks and discarding anything it thinks is an erroneous HTML tag including any text […]

Monads, Vector Spaces and Quantum Mechanics pt. II

I had originally intended to write some code to simulate quantum computers and implement some quantum algorithms. I’ll probably eventually do that but today I just want to look at quantum mechanics in its own right as a kind of generalisation of probability. This is probably going to be the most incomprehensible post I’ve written […]

Monads in C pt. III

OK, the last C monad example: typedef struct { char *string; int value; } WriterInt; WriterInt returnWriter(int i) { WriterInt r; r.string = “”; r.value = i; return r; } WriterInt bind(WriterInt (*f)(int),WriterInt x) { WriterInt y = f(x.value); WriterInt z; z.value = y.value; int len = strlen(x.string)+strlen(y.string); z.string = malloc(len+1); strcpy(z.string,x.string); strcat(z.string,y.string); return z; […]

Monads in C, pt. II

This is a quick followup to a post on reddit. This time a crude approximation to the Maybe monad implemented in C: include <stdio.h> typedef struct { int something; int just; } MaybeInt; MaybeInt returnMaybe(int i) { MaybeInt r; r.something = 1; r.just = i; return r; } MaybeInt nothing(){ MaybeInt r; r.something = 0; […]