ファンクタであそぼう

この記事はHaskell Advent Calendar 2013の3日目の記事です。

どうして?

ファンクタはHaskellに欠かせないものですが、ファンクタを一般化して見るという見方は意外に広まっていないように感じます。分かってしまえば単純な話だけにもったいないと思ってこの記事を書くことにしました。

また、僕は最近Thornというライブラリを作りました。これは、さまざまなデータ型から関手や畳み込み・展開をTemplate Haskellを使って自動生成するライブラリです。このライブラリを作るなかで気づいたことも合わせて書いていこうと思います。




ファンクタを拡張しよう

Haskellerなら誰しもファンクタは知っていることだと思います。言うまでもなく便利なファンクタですが、実はもっと拡張できます。

続きを読む

Scary Monsters And Nice Sprites の本当の歌詞

Skrillexの"Scary Monsters And Nice Sprites"はとても有名ですね。

とげとげした部分とやわらかい部分を上手に混ぜた感じで、聞きやすい音楽でいいと思います。

さて、この曲では女性の歌声が何回か出ています。この歌詞が問題です。
途中は声を反転させていてよく分からない感じです。ここはとりあえずいいとします。
最後の部分(3:18〜)にようやく聞き取れる部分が来ます。しかしなんとなく聞き取れるのですが、最初のフレーズだけどうも分からないのです。

この部分は多くの歌詞サイトで以下のように書かれています。
Look at this
I'm a coward too
You don't need to hide, my friend
For I'm just like you
最後の三行は正しいと思うのですが、最初の部分はどう聞いても"Look at this"には聞こえないのです(意味は確かに通るのですが)。最後の子音ははっきり"st"と言っています。

何度も聞いて考えた結果、次の歌詞が正しいと思いました。
How come, Christ
I'm a coward too
You don't need to hide, my friend
For I'm just like you
全体だと、「まあどうして。私も臆病なの。隠れないでいいよ、ねえ。私は君と同じだから。」くらいの意味です。
"Christ"が少し怪しいですが、強い言葉なのであえて加工したのかもしれません。

まあ実際のところはSkrillex本人に聞かないと分からないところです。

Land of Lisp の歌を訳して見た

"Land of Lisp lyrics"と調べてみると、ミュージックビデオの歌詞を訳している人がいたのですが、その訳はちょっと違うな、という部分があったりしたので、折角だし僕は僕で訳して見ることにしました。ちなみに僕は基本HaskellerでLispは見習いで、Land of Lispはまだちゃんとは読んでいません。気楽な気持ちで訳したので楽しんでいただければと思います。
脚韻したり、七五調にしたり、ちょっと工夫してみました。


 A long time ago, a young Lisper was reading an Eighties games magazine, you know, the kind with code for BASIC games printed in it.
 遠い昔、ある若いLisperは80年代のゲーム雑誌を読んでいた。それでそこにはBASICのゲームのコードなんかが書いてあった。

 And he thought to himself: "You know what would be AWESOME? A book with game code in it just like this. But which teaches all the important concepts of Lisp programming!"
 彼は考えた。「どんなものを作ったらヤバイだろう?こんなふうにゲームのコードが書いてある本で、しかもLispでのプログラミングの重要な概念を全部教えるような本だ!」

 It would use the grandaddy of the Lisp languages: Common Lisp! But would teach all the important*1 ideas for all the Lisp dialects whether Clojure, Scheme, Arc, or Emacs Lisp. So he decided he would write this book.
 この本はLispのお爺さん、Common Lispを使うんだ!でもLispのどんな方言でも、Clojureでも、Schemeでも、Arcでも、Emacs Lispでも使えるような、あらゆる重要な考えを教えてくれるんだ。そして彼はこの本を書くことに決めた。

 Time passed. It took two years for the book to become available for preorder on Amazon. But alas, the Lisper had underestimated the difficulty of teaching the most advanced Lisp concepts by writing games. And the book got delayed, and all the preorders had to be cancelled.
 時は過ぎた。この本がAmazonで先行予約できるようになるまでに2年かかった。しかし悲しいかな、LisperはLispの最も先進的な話題をゲームを書くことで教えるということの難しさを甘く見ていたのだ。そして出版は遅れ、先行予約はすべて取り消しにならざるを得なかった。

 Another year passed, and then, AFTER THREE YEARS this new book was finally ready.
 さらに1年が過ぎ、3年を経てついにこの新しい本は準備ができたのだ。

 What was it called? ―THE LAND OF LISP!
 それも名づけて ―Lispの国!


One day I got bored with Java.
So I learned a little Lisp,
and what I found was a surprise:
ある日僕はJavaに飽きて
ちょっとLispを勉強してみたんだ
そして驚いてしまった

It is a language so unique and so expressive,
so that coding never looks the same within my eyes.
唯一無二で表現力豊か
プログラミングの見え方はまるっきり変わってしまった

Now I eat parentheses for breakfast.
And if my program isn't done,
I eat parentheses for lunch.
今や朝ごはんには丸括弧
プログラムが出来ていなかったら
昼ご飯には丸括弧が最適

They might look*2 funny,
but they have semantic power
that gives your programs lots of brevity and punch!
括弧は可笑しくみえるかもしれないけど
無限の意味を秘めている
括弧を使ったプログラムは簡潔で刺激的

(*)
Simple but refined,
guaranteed to blow your mind.
The Land of Lisp
Minimal and sleek,
but still so clever you will*3 freak.
The Land of Lisp
単純だけど練られてる
絶対脳にビンと来る
Lispの国
最小限でカッコいい
頭良すぎてビビるくらい
Lispの国


Attack of the Robots

Evolution

In Lisp, we don't force everything to be an object.
We just write a bunch of functions,
higher-order is preferred.
Lispではなんでもかんでもオブジェクトにしなくていいんだ
関数をいっぱい書くんだ
高階なほうがいいからね

That way you can combine your code in richer ways
because the lack of state will always be ensured.
そうしてコードをより高度に組み合わせられるんだ
副作用が全くないからね

(*)repeat

One, Two, Three, Four!

Every programmer should learn a little Lisp!
It will give you insights into programming
you can't get anywhere else.
すべてのプログラマLispを学んでみるべし
プログラミングの深層を理解できるんじゃ
ほかの言語では駄目なんじゃ

Seriously... give Lisp a shot.
You won't regret it!
真面目な話...Lispをやってみなさい
後悔はしないぞ


Dice of Doom

Orc Battle

Advanced Lispers are not normal.
They use macros in their code
and are a truly different breed.
凄いLisperは普通じゃない
マクロを使う奴らでほんとたまげる

Any problem they want to solve
they convert Lisp into a "domain specific language"
that can do exactly what they need.
どんな問題を解決したいときでも
Lispドメイン特化言語に変えてやりたいことをやってのける

There is nothing cooler than a macro.
They make metaprogramming and DSLs a piece of cake.
マクロよりカッコいいものはない
マクロを使えばメタプログラミングDSLは朝飯前

Create your own mini-language
to parse XML, rate stocks, draw charts,
or balance weasels on a rake!
君自身のミニ言語を作ろう
XMLをパースしたり、株価を予測したり、図を描いたり
それか熊手に乗ったイタチのバランスを取ってしまえ

(*)repeat

*1:原文import

*2:原文luck

*3:原文you'll

校歌を英訳してみた

自分の通う高校の校歌を英訳してみました。



Sheik eye Nick cargo yack coup, work gar he knock coo neo.
Nina ones and toe knock evil knee mow eight day.

Less sour hug gook coup moo, on a cone not pseudo ye.
Cheek allow at soot check all, can gene amour so bee?

Higher ray, nod a corps!
Ah, wag a bore corps!


Sail York then your jitter key owe way know.
Cause any cock a loner car gummier meager quay.

Manner beat a woo muzzle loo, on a cone not pseudo ye.
To tom mate a yammers Al, can gene amour so bee?

Higher ray, nod a corps!
Ah, wag a bore corps!



意味が分からない方はこちらへお越しになれば分かるかもしれません(^o^)
Google翻訳