Librarian of Alexandria

Haskell records have lots of problems. Here's one that came up for me today.

You are allowed to export record members without exporting the constructor, for example, if you want to ensure some property is true of the constructed values. In the following example, the field isNeg is effectively a function of the field num:

module Foo(mkRec, num, isNeg) where

data Rec = Rec { num :: Int , isNeg :: Bool }

mkRec :: Int –> Rec mkRec n = Rec n (n < 0)

Another module can't use the Rec constructor, but can observe the values using the exported accessors

module Bar where

addRecs :: Rec –> Rec –> Rec addRecs r1 r2 = mkRec (num r1 + num r2)

Unfortunately, there's a hole here, which is that exporing the accessors allows us to use record update syntax, which means that we can now construct arbitrary values:

constructAnyRec :: Int –> Bool –> Rec constructAnyRec n b = mkRec 0 { num = n, isNeg = b }

There is a way around this, namely, by rewriting the original module with manual accessors for num and isNeg:

module Foo2(mkRec, num, isNeg) where

data Rec = Rec { _num :: Int , _isNeg :: Bool }

num :: Rec –> Int num = _num

isNeg :: Rec –> Bool isNeg = _isNeg

mkRec :: Int –> Rec mkRec n = Rec n (n < 0)

However, I'd assert that, morally, the correct thing to do would be to disallow record update at all if the constructor is not in-scope. The purpose of hiding the constructor at all is to ensure that a programmer must perform certain computations in order to construct a valid value, e.g. to enforce invariants on constructed data (as I'm doing here), or to avoid the possibility of pattern-matching on data. If you a programmer hides a constructor but exports its accessors, then generally I'd assert it's because of the former reason, so it would be sensible to prevent record update, as you could always write your own updates, if you so desire.

Of course, pointing out this flaw in light of the other problems with the Haskell record system is like complaining about the in-flight movie on a crashing plane, but still.

#programming

It's fun to reread Mark Twain's Fenimore Cooper's Literary Offenses and mentally replace “Deerslayer” with “Game of Thrones”. Somehow, the essay stays exactly as apt.

There are nineteen rules governing literary art in domain of romantic fiction — some say twenty-two. In “Game of Thrones,” Martin violated eighteen of them. These eighteen require:

  1. That a tale shall accomplish something and arrive somewhere. But the “Game of Thrones” tale accomplishes nothing and arrives in air.

  2. They require that the episodes in a tale shall be necessary parts of the tale, and shall help to develop it. But as the “Game of Thrones” tale is not a tale, and accomplishes nothing and arrives nowhere, the episodes have no rightful place in the work, since there was nothing for them to develop.

  3. They require that the personages in a tale shall be alive, except in the case of corpses, and that always the reader shall be able to tell the corpses from the others. But this detail has often been overlooked in the “Game of Thrones” tale.

  4. They require that the personages in a tale, both dead and alive, shall exhibit a sufficient excuse for being there. But this detail also has been overlooked in the “Game of Thrones” tale.

  5. They require that when the personages of a tale deal in conversation, the talk shall sound like human talk, and be talk such as human beings would be likely to talk in the given circumstances, and have a discoverable meaning, also a discoverable purpose, and a show of relevancy, and remain in the neighborhood of the subject at hand, and be interesting to the reader, and help out the tale, and stop when the people cannot think of anything more to say. But this requirement has been ignored from the beginning of the “Game of Thrones” tale to the end of it.

  6. They require that when the author describes the character of a personage in the tale, the conduct and conversation of that personage shall justify said description. But this law gets little or no attention in the “Game of Thrones” tale, as Daenerys Targaryen's case will amply prove.

  7. They require that when a personage talks like an illustrated, gilt-edged, tree-calf, hand-tooled, seven- dollar Friendship's Offering in the beginning of a paragraph, he shall not talk like a Dothraki stereotype in the end of it. But this rule is flung down and danced upon in the “Game of Thrones” tale.

  8. They require that crass stupidities shall not be played upon the reader as “the craft of the Night's Watch, the delicate art of the forest,” by either the author or the people in the tale. But this rule is persistently violated in the “Game of Thrones” tale.

  9. They require that the personages of a tale shall confine themselves to possibilities and let miracles alone; or, if they venture a miracle, the author must so plausibly set it forth as to make it look possible and reasonable. But these rules are not respected in the “Game of Thrones” tale.

  10. They require that the author shall make the reader feel a deep interest in the personages of his tale and in their fate; and that he shall make the reader love the good people in the tale and hate the bad ones. But the reader of the “Game of Thrones” tale dislikes the good people in it, is indifferent to the others, and wishes they would all drowned together.

  11. They require that the characters in a tale shall be so clearly defined that the reader can tell beforehand what each will do in a given emergency. But in the “Game of Thrones” tale, this rule is vacated.

In addition to these large rules, there are some little ones. These require that the author shall:

  1. Say what he is proposing to say, not merely come near it.

  2. Use the right word, not its second cousin.

  3. Eschew surplusage.

  4. Not omit necessary details.

  5. Avoid slovenliness of form.

  6. Use good grammar.

  7. Employ a simple and straightforward style.

Even these seven are coldly and persistently violated in the “Game of Thrones” tale.

Frankly, I don't dislike Game of Thrones, but as a television show, at least, it has more in common with theme-park rides or pornography or the movie Avatar than it does with serious works of fiction. Game of Thrones exists for the experience of Westeros, which is why every conversation involves ten sentences of fake formalities and faux-medieval dialogue for every relevant fact, while each of the thousand paper-thin characters has a single goal and pursues that goal while evincing their single defining trait (Littlefinger is duplicitious and protects Catelyn; Tyrion is clever and pursues power; Joffrey is a jackass and pursues more jackassery.)

Game of Thrones not meant to have any kind of depth or complexity—-it's meant to appear that there is depth and complexity just behind the curtain, so that as you sit with your arms and legs inside the ride, you feel like the characters are people instead of animatronic dummies. Space Mountain can't take you to space, and pornography can't make you feel sexual intimacy, but they can emulate the feeling of it. Game of Thrones emulates the feeling of experiencing a complicated and nuanced story without ever giving you the story. It is, in that sense, effective without ever being good.

#silly

I'm working on a programming language called Rubbish. It is called Rubbish because it is rubbish. Nobody should use it. I will not use it beyond its simple purpose, which is a personal thought experiment.

If this appeals do you, then learn Lisp instead. All dynamic languages are Lisp with a handful of macros and a modicum of discipline, anyway.

In practice, the Rubbish language will have a handful of built-in types—-an integer type, a floating point type, a string or rope or something—-but, for our purposes, let's assume it has only two types: variants and functions. These two are the only two currently accounted for in the semantics, which I will type up at some point.

Rubbish is weakly typed, so only values have an associated type; variables can take on any type. The primary data type mechanism is the variant, which are analogous to the tagged sums of strongly typed functional languages except without type guarantees. A variant has an obligatory name, which begins either with a capital letter (e.g. Foo), and an optional tuple of expressions, which are evaluated in sequence and stored along with the tag name. Variants are immutable, so there is no mechanism for changing the tag, the values stored with the tag, or the number of values. (If the values themselves are mutable, then they may of course be changed.)

The only meaningful operations on variants are equality and pattern matching; equality may be seen as a deficient form of pattern-matching. Pattern-matching is the only way of extracting information from a variant. For example:

rsh> mypoint := Foo(One, Two) rsh> mypoint = Foo False rsh> mypoint = Foo(Two, One) False rsh> mypoint = Foo(One, Two) True rsh> match my_point { Foo –> Nullary Foo(x) –> Unary(x) Foo(x, y) –> Binary(y, x) Foo(x, y, z) –> Ternary(z, y, x) _ –> Other } Binary(Two, One)

We can use them as a cheap and easy way to define the Peano numbers.

rsh> add := fun(x, y): match x { Zero –> y Succ(x') –> add(x', Succ(y)) }

I plan on eventually implementing user-definable mix-fix operators, so you could eventually write the following:

rsh> + := add rsh> Succ(Succ(Zero)) + Succ(Succ(Succ(Zero))) Succ(Succ(Succ(Succ(Succ(Zero)))))

The other type is functions, which are introduced with the fun keyword and take a tuple of arguments. There is another syntax for functions of one argument, and it looks kind of like a hash literal. The definitions of isZero and isZero' below have identical functionality. (Notice that this means match x cases is basically syntactic sugar for cases(x).)

rsh> isZero := fun(x) –> match x { Zero –> True _ –> False } rsh> isZero' := { Zero –> True _ –> False } rsh> isZero'(Succ(Zero)) False rsh> isZero'(True) True

Combine this with the following sprinkling of syntactic sugar:

. := fun(f, x): f(x)

And we get the following:

rsh> makePoint := fun(x, y): { IsOrigin –> x = 0 and y = 0 GetX –> x GetY –> y Add(p) –> makePoint(x + p.GetX, y + p.GetY) ToString –> format(“Point({0}, {1})”, x, y) method –> raise MethodNotFound(method) } rsh> a := makePoint(2, 3) rsh> b := makePoint(4, 5) rsh> a(IsOrigin) False rsh> a.IsOrigin False rsh> a.ToString “Point(2, 3)” rsh> a.Add(b).ToString “Point(6, 8)” rsh> a.Add(makePoint(-2,-3)).IsOrigin True

While variants can encode data, functions like these can easily encode codata like streams.

rsh> ones := { Head –> 1 Tail –> nats } rsh> streamMap := fun(f, stream): { Head –> f(stream.Head) Tail –> streamMap(f, stream.Tail) } rsh> nats := { Head –> 1 Tail –> streamMap(fun(x): x + 1, nats) } rsh> take := fun(num, stream): match num { 0 –> Nl _ –> Cs(stream.Head, take(num – 1, stream.Tail)) } rsh> take(5, ones) Cs(1, Cs(1, Cs(1, Cs(1, Cs(1, Nl))))) rsh> take(5, nats) Cs(1, Cs(1, Cs(3, Cs(4, Cs(5, Nl)))))

Finally, because of mixfix operator definition, we are free to do some pretty horrific things. I am omitting precedence declaration here because I haven't decided on a syntax for it yet.

rsh> –> := . rsh> nats->Tail->Head 2 rsh> <- := fun(x, f): f(x) rsh> Head<-Tail<-nats 2

That's some Rubbish for you. There's one major feature I haven't covered yet, and that's delimited continuations. As I said before, if any of this appeals to you, then you are a horrible human being, but I would recommend a healthy dose of Scheme, ML, or Haskell.

#programming

What is the trait you most deplore in yourself?

Indifference to the plights of others.

What is the trait you most deplore in others?

Their sleazy readiness to offer me help when I don't need or want it.

What makes you depressed?

Seeing stupid people happy.

What do you most dislike about your appearance?

That it makes me appear the way I really am.

What does love feel like?

Like a great misfortune, a monstrous parasite, a permanent state of emergency that ruins all small pleasures.

What or who is the love of your life?

Philosophy. I secretly think reality exists so we can speculate about it.

Have you ever said 'I love you' and not meant it?

All the time. When I really love someone, I can only show it by making aggressive and bad-taste remarks.

What is the worst job you've done?

Teaching. I hate students, they are (as all people) mostly stupid and boring.

What is the most important lesson life has taught you?

That life is a stupid, meaningless thing that has nothing to teach you.

—-Q&A: Slavoj Žižek

#quotes

This is what I'm thinking about as I watch The Legend of Korra, which takes place in the same fictional universe as Avatar: The Last Airbender.

Proposal 1: The Genetic Basis of Bending


There are five alleles: w for waterbending, e for earthbending, a for airbending, f for firebending, and N for no bending. The first four are recessive, i.e. ww is the genotype of a waterbender, aa of an airbender, but a wa displays no bending whatsoever.

The final allele, N, blocks all bending in the person who has it. If two people reproduce, one of whom is ff and the other of whom is NN, then despite one parent being a firebender, none of their children will ever be a bender, because all will exhibit the genotype Nf. N is a dominant allele.

In the original series, Sokka and Katara are both members of the water tribe, but Sokka is not a waterbender while Katara is. Their father Hakoda is not a bender, while their mother Kya is. We can therefore surmise that Hakoda's genotype is Nw, Kya's is ww, and, by Punnett square:

| N | w —————- w | Nw | ww w | Nw | ww

Sokka's genotype is Nw, i.e. no expressed bending, while Katara's is ww, i.e. she is a waterbender.

This is consistent with Bolin and Mako in Korra. Bolin is an earthbender and Mako is a firebender, but the two are brothers. Consequently, Bolin must have ee and Mako ff, so both of their parents must be ef:

| e | f —————- e | ee | ef f | fe | ff

This analysis seems to fit most of the show.

Proposal 2: Account for Aang's Descendents


Aang has three children: Kya, Bumi, and Tenzin. Kya is a waterbender, Tenzin is an airbender, and Bumi does not bend. Bumi is well-explained by the previous proposal, as his genotype would be aw, a non-bending type. But how to account for the other two?

Let us posit a sixth allele: C is the most recessive allele, and as such enables any other kind of bending. A person with the Ca genotype would be an airbender, Cw a waterbender, and so forth; CN would still be a non-bender. In effect, C enables the other allele to take effect.

Now, we revise our analysis of Sokka and Katara's lineage. Suppose that Hakoda, instead of Nw, were instead NC:

| N | C —————- w | Nw | Cw w | Nw | Cw

Now, Sokka's genotype is Nw, while Katara's is Cw. Sokka is still a non-bender, and Katara is still a waterbender. Now Katara reproduces with Aang (Ca):

| C | w —————- C | CC | Cw a | Ca | aw

Their children can have one of three possible phenotypes: either airbending (genotype Ca), waterbending (Cw), or neither (CC or aw), giving Tenzin's genotype as Ca. His wife Pema either has a recessive airbending trait, so that their children have aa genotypes, or a C allele, so that their children have Ca genotypes. The latter seems more likely.

Accounting for the Avatar


How do we make room for the Avatar, who can bend all four elements? Above I suggested that Aang's genotype was Ca, which enabled us to make the square for Aang and Katara's children work. But what enables the Avatar to bend all four elements?

Magic. Just magic. Fuck you.

#silly

It is entirely possible that this blog will devolve into the Warren Ellis quoting hour.

Dance like you're stamping on a human face forever, love like you've been in a serious car crash that minced the front of your brain, stab like no one can arrest you, and live like there's no such thing as God.

—-Warren Ellis

Oh, wait, did I say devolve? I meant evolve.

#quotes

(And I'm interested, I realise, because I want Network Realism for precisely the same reasons that Moorcock and Stross decry the aesthetisisation of steampunk: because the aesthetisisation of anything is an abdication of its politics, because the aesthetisisation of politics is fascism, and fascism is the opposite of imagination. We have too many dead literatures.)

—-Starpunk, James Bridle

#quotes

Cascading recombinance from Matt Webb

all of this is nothing compared to what will be.

this is early email, rabbit phones. this is technology demo, scoping the terrain and guessing what's going to be

in the future the infosphere will be as aether around us and you'll be able to make hiphopalikes by the dozen in five minutes

every cool thing made today is a dead end. each thing pulls together strands of technology and makes a knot, then leaves it.

but in the future every thing will also be a strand, ready to be knotted. and this'll happen suddenly. there'll be a way to combine and recombine, to mix and match, platforms and media and messages.

one day soon we'll get there, then it'll be a cascading recombinance and everything you play with now will be redundant. but that's okay, because you'll be able to make it yourself like that ><

it's *about* to happen on the www, very very soon now. and as that permeates the collective unconscious, it'll happen in the real world too.

#quotes

My mother recently wrote a poem warning against eating her food—-as she is not known to be a prolific cook—-and posted it in the kitchen. It went like this:

He who eats here\ Must trust his fate\ To please his palate\ And fill his plate\ Sometimes there is\ Sometimes there ain't\ I'm not a cook\ I like to paint

I responded to this abomination with a poem of my own:

I found the bane of Euterpe\     one dismal winter day\ A poem so bereft of skill\     I thought my mind would fray\ Into a million tiny threads—-\     it would have been more pleasant\ Than living with its memory\     as I do in the present.

For in the many brilliant years\     when poems were composed\ No single dumb, ungainly fool\     had ever yet proposed\ To write a poem with such a rhyme\     to make the muses faint\ And throw decorum to the wind\     by rhyming “paint” with “ain't.”

#stories

Isaac [Newton], though better equipped than Daniel or any other man alive to understand Relativity, showed no interest in his pie—-as if being in a state of movement with respect to the planet Earth rendered it somehow Not a Pie. But as far as Daniel was concerned, a pie in a moving frame of reference was no less a pie than one that was sitting still: position and velocity, to him, might be perfectly interesting physical properties, but they had no bearing on, no relationship to those properties that were essential to pie-ness. All that mattered to Daniel were relationships between his, Daniel's, physical state and that of the pie. If Daniel and Pie were close together both in position and velocity, then pie-eating became a practical, and tempting, possibility. If Pie were far asunder from Daniel or moving at a large relative velocity—-e.g., being hurled at his face—-then its pie-ness was somehow impaired, at least from the Daniel frame of reference. For the time being, however, these were purely Scholastic hypotheticals. Pie was on his lap and very much a pie, no matter what Isaac might think of it.

—-Neal Stephenson, “The Baroque Cycle”, Vol. 3: “The System of The World”, Book 7: “Currency”, p. 457

#quotes