これは [Haskell Advent Calendar 2012][] の11日目の記事です。
Haskell でデータ設計を便利に行う発想・方法について書きました。
[persistent][] というライブラリを活用します。
Haskell を知らなくても読めます。
主な対象読者は [プログラミングHaskell][] か [すごいHaskellたのしく学ぼう!][] を読み、Haskell をより使いたい人です。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package niochat; | |
| import java.net.*; | |
| import java.nio.*; | |
| import java.nio.channels.*; | |
| import java.io.IOException; | |
| import java.util.*; | |
| public class NiochatServer implements Runnable { | |
| private final int port; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # source : http://code.google.com/p/natvpn/source/browse/trunk/stun_server_list | |
| # A list of available STUN server. | |
| stun.l.google.com:19302 | |
| stun1.l.google.com:19302 | |
| stun2.l.google.com:19302 | |
| stun3.l.google.com:19302 | |
| stun4.l.google.com:19302 | |
| stun01.sipphone.com | |
| stun.ekiga.net |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 「あるプログラミング言語を一通り触る」という目標を達成するのに必要な課題の集合はなにか? | |
| "Hellow World" | |
| まずはこれ | |
| 標準出力、実行環境 | |
| "fizzbuzz" | |
| if文, mod |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Latency Comparison Numbers (~2012) | |
| ---------------------------------- | |
| L1 cache reference 0.5 ns | |
| Branch mispredict 5 ns | |
| L2 cache reference 7 ns 14x L1 cache | |
| Mutex lock/unlock 25 ns | |
| Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
| Compress 1K bytes with Zippy 3,000 ns 3 us | |
| Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
| Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data ExprP = Var String | Apply ExprP ExprP | Lambda String ExprP -- lambda calculus expression | |
| data Expr = I | K | S | Expr :$ Expr | Free String -- combinatory expression | |
| compile :: ExprP -> Expr | |
| compile (Apply f x) = compile f :$ compile x | |
| compile (Lambda p e) = bindee p $ compile e | |
| compile (Var i) = Free i | |
| bindee :: String -> Expr -> Expr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define (while1 cond body) | |
| (let ((c (call/cc (lambda (c) c)))) | |
| (if (cond) | |
| (begin | |
| (body) | |
| (c c))))) | |
| (define i 0) | |
| (while1 (lambda () (< i 10)) | |
| (lambda () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import qualified Control.Monad.State as S | |
| import Control.Applicative ((<$>), (<*>)) | |
| import Data.Maybe (fromMaybe) | |
| import qualified Data.Map as M | |
| import Control.Monad (unless) | |
| data BF = Token Char | Loop [BF] deriving Show | |
| type Tape = M.Map Int Char | |
| type Env = (Int, Tape) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $input = json_decode(file_get_contents("php://input"), true); | |
| $source = $input["events"][0]["message"]["text"]; | |
| define("PHP_SIGN", "<?"); | |
| define("LLEVAL_ENDPOINT", "http://api.dan.co.jp/lleval.cgi"); | |
| if (0 === strpos($source, PHP_SIGN)) { | |
| echo prep($source); |