日本語でArrowの説明があまり見付からなかったので、Haskell/Understanding arrows - Wikibooks, open books for an open worldを読んで理解したつもりのメモ。オリジナルの図を見ながらだと分かりやすいかも。誤り・間違いなど、乞うご指摘。 b->cな関数をArrowなるからくり箱に入れると、 (Arrow a) => a b c こんな型になる。型パラメタが、引数のbと返値のcのふたつ。 Monadは、値をからくり箱に入れたもの。からくり箱は基本的に(ヘンな)値。 Arrowは、関数をからくり箱に入れたもの。からくり箱は基本的に(ヘンな)関数。 arr :: (b -> c) -> a b c Monadでは、値をからくり箱に入れる関数returnがある。 Arrowでは、関数をからくり箱に入れる関数arrがある。 (>>>)
While playing around with querying ElasticSearch I bumped into something that I hadn't really understood explicitly before about monads, nesting, and IO. Rather than blather on, I'm going to share a "literate" ghci session that demonstrates the point. Main editing change I made was to remove duplication in the output from querying the type :t in ghci. import Network.HTTP import Control.Monad (join
「モナドは象だ(Monads are Elephants)」日本語訳 — Japanese Translation of Monads are Elephants v1.0 documentation読み終わりました. JavaからScalaに行った人には比較的分かりやすい説明だったと思います. ちなみに4章でぎり頭爆発. ほとんど抜粋ですが,自分用のまとめとして保管させて頂きます. 何か問題あれば,即削除しますのでコメントなどで連絡お願いします. Tips “=> A”は、call by name(名前渡し)と呼ばれる指定方法で、引数を遅延評価します。通常、foo( bar )という呼び出しではbarが評価された結果をfooの引数として渡しますが、fooメソッドの定義が”def foo( v: => String)”のように定義されていると、barをいわゆる無名関数に包んでfooメソッド
hackage.haskell.org の Control.Monad.Error 文書には Error モナドのモナド・トランスフォーマーである ErrorT の使い方の例が紹介されている。次のプログラムがそれだ。原著からのコピペでそのまま動いた。 import Control.Monad.Error -- An IO monad which can return String failure. -- It is convenient to define the monad type of the combined monad, -- especially if we combine more monad transformers. type LengthMonad = ErrorT String IO main = do -- runErrorT removes the ErrorT
State モナドの使い方がもうひとつよく分からなかったので、State Monad のチュートリアルを読んでいたら、Parsec と同じ使い方をすれば良いのだと気がついた。 Parsec ではパーサのモナドをプログラムしても、それだけでは何もしてくれない。たとえば、Parsec の(プリミティブ)関数の letter は、次のように parser 関数の引数にして実行しないとなにもしない。 Prelude Text.Parsec> parse letter "" "hello" Right 'h' また、要素的 (primitive) な関数はパーサーコンビネータと組み合わせることによって複雑なパターンに対応することができる。 Prelude Text.Parsec> parse (many1 letter) "" "hello world" Right "hello" さらに、パーサ関
ReaderからStateへ 函数モナド a.k.a. Readerモナドをある程度理解したので、Stateモナドまで足を伸ばしてみようというわけである。文系情弱にStateモナドが理解できるのだろうか。 Stateは「状態」を表現する型sと「値」を格納する型aを取る。函数モナドで見たように、これはState s型のモナドで、sが共通のモナド同士でやりとりをすることになる。型図式のmがState sになるわけね。 超基礎的なところから考えなおしてみる。まず、Haskellで「状態」を実現する一番簡単なやり方は、引数を増やして状態を渡していくことだ。一番初歩的な例は階乗函数の定義に蓄積引数を使うやり方である。またIOモナドが実は隠れた引数として「世界の状態」を取っていると考えられるのと同様にして、状態に応じて挙動を変える函数とは、「状態」を表現するような引数を持つ函数にほかならない。 Sta
2020/02/10 · 今回取り上げる状態系モナドは次の5つです。 STモナド; Stateモナド; Readerモナド; Writerモナド; 関数モナド. ※ 厳密な分類ではないため、人によって別 ...
I would like Haskell better if it didn’t do its best to make me feel stupid. Tasks that are easy in other languages, such, say, maintaining some state or generating a random number, become difficult. After banging my head on the State monad I finally arrived at a kind of understanding, which I put here so I can restore context in the future! Presume that you’ve got a function that, given a list, r
As anyone who reads this blog knows, my favorite programming language is Haskell. I love functional programming, and Haskell is a great vehicle for pushing functional programming to its limits. However, I try to keep up with other up-and-coming languages, especially functional ones, so of course I've been aware of Scala ever since it came out. At the time, I took a cursory look at it and didn't li
While working on an article for the Monad.Reader, I’ve had the opportunity to think about how people learn and gain intuition for abstraction, and the implications for pedagogy. The heart of the matter is that people begin with the concrete, and move to the abstract. Humans are very good at pattern recognition, so this is a natural progression. By examining concrete objects in detail, one begins t
Here’s a nice quip from Luke Gorrie on Twitter: Monads are hard because there are so many bad monad tutorials getting in the way of finally finding Wadler’s nice paper. Here’s the paper by Philip Wadler that I expect Luke Gorrie had in mind: Monads for functional programming. Here’s the key line from Wadler’s paper: Pure functional languages have this advantage: all flow of data is made explicit.
UPDATE (2014/03/01) It turns out that there was a better way to do this, please see this new post. Rationale I am currently experimenting with the operational package. This post provides a rough outline on how I moved from an IO based monad stack to an isomorphic pure representation of the computation. I am unfortunately not well endowed on the theoretical side, so this will be a very practical po
The Haskell programming language community. Daily news and info about all things Haskell related: practical stuff, theory, types, libraries, jobs, patches, releases, events and conferences and more...
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く