2005-01-01から1ヶ月間の記事一覧

http://www.lab2.kuis.kyoto-u.ac.jp/~hanatani/tdiary/?date=20050110 辺彩色という概念があるんですね。単調増加の意味はわかりません…

昨日の[Puzzle] 情報共有と電話の回数[id:yts:20050110]に追記。

google:気をつけろ スタンド攻撃だ

Hack Parsec

Parsecを少し改造*1した。whiteSpaceなどの定義を(矛盾無く)変更できるようにした。 module Test where import Text.ParserCombinators.Parsec as P import Text.ParserCombinators.Parsec.Language as P import Text.ParserCombinators.Parsec.Char as P im…

情報共有と電話の回数

私「N人の人がいて、その人たちはみんなすでに秘密を共有しているとする。そこにもう1人の人がやってきたとする」長男「なるほど。その人のことを知るのにN回電話が必要なんだね」私「その通り。情報がどこかでまとまるとしても、N人の人は少なくとも電話を1…

LCD Numbers

Quiz: [QUIZ] LCD Numbers (#14) via: http://www.sampou.org/cgi-bin/cahier.cgi?blog%3aCahier%3a2005-01-08 (日付指定のリンクはできないのだろうか?)コメントで教えて頂きました。 module Main where import Data.Array (listArray, (!)) import Data.L…

巡回置換の積 (2)

http://www.sampou.org/cgi-bin/haskell.cgi?blog%3aEveryday%3a2005-01-04&l=jpより。篩い。 sieve _ [] = [] sieve elem (x:xs) = x:sieve elem [y | y <- xs, not (head y `elem` x)] orbits elem span = sieve elem . map span数学的にはelemはパラメー…

巡回置換の積

http://www.sampou.org/cgi-bin/haskell.cgi?blog%3aEveryday%3a2005-01-04&l=jpより。 import Data.Graph (stronglyConnComp, flattenSCC) toCycles xs = filter ((1 /=) . length) $ map flattenSCC $ stronglyConnComp [(x, x, [y]) | (x, y) <- xs]*D050…

Continuation Monad (3)

[Haskell] Continuation Monad (2) [id:yts:20050103#p1] の続き。 13.3 Tree matching まずTree型の定義をしておく。 data Tree a = Tree [Tree a] | Leaf a deriving (Eq, Show) car (Tree (x:xs)) = x cdr (Tree (x:xs)) = Tree xs isNull (Tree []) = Tr…

ZipN

率直な感想…構文木を作るコード書くのめんどくさすぎ…自分で書こうと思っても全然書けない。慣れの問題なのだろうか…? 2004-12-27 「構文木」というのを意識しすぎなのだと思います。 例3 任意個のzip (引用略) zip3 = $(zipN 3)と書ければ嬉しいという話。 …

Continuation Monad (2)

[Haskell] Continuation Monad (1) [id:yts:20050102#p2] の続き。 13.2 Escaping continuations Example (define list-product (lambda (s) (call/cc (lambda (exit) (let recur ((s s)) (if (null? s) 1 (if (= (car s) 0) (exit 0) (* (car s) (recur (cd…

可変長引数の関数?

Movedのminor nit. イヤなことにはかわりなし。 class VAFun a r f | f -> r where withVAList :: ([a] -> r) -> f instance VAFun a Int Int where withVAList g = g [] instance VAFun a r x => VAFun a r (a -> x) where withVAList g x = withVAList (g …

Continuation Monad (1)

t-y-schemeの継続についての章であるChapter 13をHaskellで書いてみる。まず13.1章。 13.1 call-with-current-continuation Example 1 (+ 1 (call/cc (lambda (k) (+ 2 (k 3))))) => 4 Continuationモナドを利用する。(+)や整数リテラルがtype classのメソッ…

新年おめでとうございます。