Control.Category モジュールを用いて多価函数1 の合成について考えてみます. 余力があればより有用な Control.Arrow モジュールについて見ていきたいです. GHC, GHCi を使う環境を想定しています. 次の記事 → 綱渡りと Category (と,Kleisli) 多価函数 多価函数とは 与えられた数 x に対して,その平方根を返す函数について考えてみます. 例えば 4 の平方根は 2 と -2, 9 の平方根は 3 と -3, 17 の平方根は √17 と -√17 のように平方根は (0 等を除いて) 二つ存在することがわかります. このように入力に対して複数の出力を持つ "函数" を多価函数と呼びます. 数学においては冪根,複素数の対数函数,周期函数の逆函数などさまざまな多価函数が存在します. 多価函数は函数ではない? 函数は一般的に "1 つの入力
Milewski 氏の圏論講座の第1章 Category: The Essence of Compositionを読んでたら、冒頭あたりに次のような一文があった。 But the essence of a category is composition. Or, if you prefer, the essence of composition is a category. 射の合成こそが圏の本質で、またその逆も成り立つという。 Cats だと cats.arrowパッケージのArrowやCategoryといった型クラスで、いろいろなパターンの合成が提供されているらしい。今回はこれを調べてみた。 (Cats バージョンは 2.12の 2.0.0-M1。ソースはここ) Arrow の階層 cats.arrow パッケージ内のArrow関連の継承関係は、下図のようになる。 以降、これらの型クラ
Finally, better Arrow syntax, completely free of hacks Published on March 12, 2020 under the tag haskell Not to be taken seriously. Haskell is great building at DSLs – which are perhaps the ultimate form of slacking off at work. Rather than actually doing the work your manager tells you to, you can build DSLs to delegate this back to your manager so you can focus on finally writing up that GHC pro
最近では DDD 関連で語られることもある Functional Reactive Programming (FRP)の分野では、Arrowがよく使われてるという。Arrows-based FRP といった呼び方もあるらしい。 ただ、Scalaのライブラリに入っているのを見たことはあるけど、今まで使ったことがない。そこで今後の予習もかねて、Cats に入っている Arrow で素振りしてみる。お題は、Haskellの Arrow tutorial を選んでみた。 ちなみに自分は初見時やや混同したけど、圏論で「射(morphism)は〜で矢印(arrow)とも呼ばれる」といった文脈での arrow とこのArrow は別のもので(参考)、Freyd-category という圏の一種らしい。ただしここでは深入りせず、monad の generalization としての単なる型クラスの一つとい
これはHaskell Advent Calendar その1 8日目の記事です。 前日の記事は@nobsunさんのTree: 親子関係の付け替えでした。 対象者 すごいH読んだ 型とか型クラスわかる hlintにArrow使えって怒られたことがある 反駁不可パターンはわかる Arrowとは プログラミングには純粋な関数ではないが、関数のような雰囲気を持った構成要素が存在する。 この記事ではこれを計算と呼ぶことにする。型クラスを使えば、こういった計算に共通する構造を見つけることで、インターフェイスを提供できる。こういった抽象度の高いインターフェイスを提供することの有用性は語るまでもないだろう。ざっくり言えば実はこれがArrowである。我々が呼吸するように使う(?)Monadもこれに類するものである。ArrowはMonadと違い、複数の入力を消費できる、入力値による選択が行える、フィードバック
Incorporates strong typing over predicate logic programming, and, conversely, incorporates predicate logic programming into strongly typed functional languages. The style of predicate logic is from Prolog; the strongly typed functional language is Haskell. The Arrow class in Haskell is a generalization of the Monad class. Whereas a Monad type contains a value, and therefore is often used to repres
Introduction Gabriel Gonzalez has written quite a bit about the practical applications of free monads. And "haoformayor" wrote a great stackoverflow post on how arrows are related to strong profunctors. So I thought I'd combine these and apply them to arrows built from profunctors: free arrows. What you get is a way to use arrow notation to build programs, but defer the interpretation of those pro
I'm curious what criteria people come up with when they sit down and say, "Hmm, I should really model this with Arrows", what those problem domains tend to be, and what they achieve when Monads aren't appropriate. After tinkering with Yampa, Auto, and reading John Hughes "Programming with Arrows" paper I understand at a fundamental level how to use them, just not what the intuition is for when to
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...
アロー(Arrows; http://www.cse.chalmers.se/~rjmh/Papers/arrows.pdf)は、2000年前後にヒューズ(John Hughes)によって導入されたプログラミング手法/計算モデルです。これって面白いような、面白くないような? 僕にとってアローは微妙な概念なんですが、それはともかく、アトキー(Robert Atkey)の "What is a Categorical Model of Arrows?" によれば、アローはフレイド圏やその変種と同等なようです。 アローやその拡張では、アスキー文字を3つ続けた中置演算子が使われます。>>>、***、&&& です。これらの演算子の意味を考えてみたら、アトキーの言うフレイド圏では不足があります。対角(diagonals)という構造を入れないと、うまく説明できません。 内容: フレイド圏 対角構造 対角
12 July 2014 (programming haskell language) I've been thinking lately about arrows in relation to applicative functors and monads. The difference between the latter two is easy to intuit (and I'll describe it via an example below), but I never managed to get the same level of understanding about arrows. There's a somewhat famous paper about this question, which has a very clear-cut diagram showing
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く