A gentle introduction to write an attractive Haskell program with lens
ちゅーん tune
前回の出題にある通りです。
あらためて書くと、標準入力から与えられる文字列のなかに文字@が何回現れるかを数えてその個数を標準出力せよ、という問題でした。
| <html> | |
| <p> | |
| 良い本、普通の本は他の人が挙げると思うので、他の人が挙げなさそうなものをできるだけ選んでみます。 | |
| </p> | |
| <hr><pre> | |
| Bernhard Korte and Jens Vygen, | |
| "Combinatorial Optimization, theory and algorithms", | |
| Springer | |
| </pre> | |
| <p> |
| -- a lightweight pxeger with QuickCheck2 in Haskell | |
| -- usage: | |
| -- 1) find an example which satisfies the regex "a": | |
| -- ghci> check (mkRegex "a") | |
| -- *** Failed! Falsifiable (after 50 tests and 5 shrinks): | |
| -- "a" | |
| -- check tries at most 100 tests. here, we found within 50 tests. | |
| -- 2) search more instances with the regex "a.b" | |
| -- ghci> checkDeep 1000 (mkRegex "a.b") | |
| -- *** Failed! Falsifiable (after 316 tests and 7 shrinks): |
| -- http://atnd.org/events/46727 | |
| -- https://gist.github.com/cojna/0918920c7a246961227b | |
| import Control.Monad.State | |
| import qualified Data.Map as M | |
| type Memo = M.Map Int Integer | |
| add :: Int -> Integer -> State Memo () | |
| add k v = do s <- get |
説明はあとで(適当に)します。 このファイルを protocol.pml という名前で保存して、次の手順を踏みます:
> spin -a protocol.pml
> gcc pan.c
> ./a.out
> spin -M -t protocol.pml
以上で protocol.pml.ps という PostScript ファイルができあがります。
| Ruby の Array は関数型プログラミングの List とは違います。 | |
| が、Ruby 1.8.7 以上で Enumerable は大きく変わりました。 | |
| その結果、関数型プログラミングの文脈における List のかなりのことが、 | |
| 短いプログラム断片で書けるようになったと理解しています。 | |
| 関数型プログラミングでは、さらに List を抽象化できます。 | |
| その一つが Rose tree [Bird 1998] です。 | |
| Ruby でも、このような抽象化があれば役にたつと思います。 |
| # Current Trends on Gröbner Bases 関連文書まとめ | |
| The 8th Mathematical Society of Japan Seasonal Institute | |
| Current Trends on Gröbner Bases | |
| — The 50th Anniversary of Gröbner Bases — | |
| July 1 - July 10, 2015 | |
| http://www.math.sci.osaka-u.ac.jp/~msj-si-2015/index.html |
| ; try the following code at http://rise4fun.com/z3/tutorial | |
| ; data type Nat | |
| (declare-datatypes () ((Nat zero (succ (pred Nat))))) | |
| ; plus as a rule | |
| (declare-fun plus (Nat Nat Nat) Bool) | |
| ; rule P-Zero | |
| (assert (forall ((n Nat)) (plus zero n n))) | |
| ; rule P-succ | |
| (assert (forall ((m Nat) (n Nat) (r Nat)) | |
| (=> (plus m n r) (plus (succ m) n (succ r))))) |