タグ

関連タグで絞り込む (2)

タグの絞り込みを解除

functionalとmonadに関するmoozのブックマーク (2)

  • Iterator パターンの本質 · eed3si9n

    2011-12-17 これは Scala Advent Calendar 2011 の 17日目の記事です。 specs2 の作者であり、@etorreborre としても活発に発言を続けるシドニーの強豪 Eric Torreborre さんが書いた “The Essence of the Iterator Pattern” を翻訳しました。翻訳の公開は人より許諾済みです。翻訳の間違い等があれば遠慮なくご指摘ください。 2011年6月24日 Eric Torreborre 著 2011年12月17日 e.e d3si9n 訳 去年読んだ論文で一番気に入ったのは “The Essence of the Iterator Pattern”(以下、EIP)だ。これを読んだ後で、今まで何年も使い続けてきたあるものに対する考えがガラリと変わった。それは、for ループだ。 この論文の中からいくつか

  • モナド則三度 - あどけない話

    「モナド則再び」で書いた「モナド則1」は何の訳に立つのかという問題ですが、"Monads for functional programming" に答えが載っていました。 以下のような加算機を考えます。 data Term = Con Int | Add Term Term data M a = M a deriving Show instance Monad M where return x = M x M x >>= f = f x eval :: Term -> M Int eval (Con a) = return a eval (Add t u) = do a <- eval t b <- eval u return (a + b) 論文には、M の実装が載っていないので、適当に作りました。Maybe でもいいでしょう。 こういう風に動きます。 式1: eval (Add (Co

    モナド則三度 - あどけない話
  • 1