You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert
データ構造に対する処理を抽象化するための型クラスとして,第3回ではFunctorクラス,第34回ではFoldableクラスを説明しました。FunctorクラスやFoldableクラスでは,「データ構造の走査(traverse)」と「データ構造を走査した際に行う処理」をセットにしたfmapやfold*という処理が直接提供されています。 Haskell以外の言語が持つイテレータなどの機能では「データ構造の走査」と「データ構造を走査した際に行う処理」を切り離すことで,より一般的な処理を行えます。Haskellではそのような枠組みとして,Data.TraversableモジュールでTraversableクラスが提供されています。 mapM関数やsequence関数を一般化 まず,Traversableクラスがどのようなものかを簡単に見てみましょう。 Prelude Data.Traversable
Haskell calls a couple of historical accidents its own. While some of them, such as the "number classes" hierarchy, can be justified by pragmatism or lack of a strictly better suggestion, there is one thing that stood out as, well, not that: Applicative not being a superclass of Monad. The topic has been discussed multiple times in the past (cf. link section at the very end). This article describe
Every time I read Learn You a Haskell, I get something new out of it. This most recent time through, I think I’ve finally gained some insight into the Applicative type class. I’ve been writing Haskell for some time and have developed an intuition and explanation for Monad. This is probably because monads are so prevalent in Haskell code that you can’t help but get used to them. I knew that Applica
Written April 17, 2013 updated: May 20, 2013 Here's a simple value: And we know how to apply a function to this value: Simple enough. Lets extend this by saying that any value can be in a context. For now you can think of a context as a box that you can put a value in: Now when you apply a function to this value, you'll get different results depending on the context. This is the idea that Functors
An success story of Arrows Published on January 14, 2012 under the tag haskell This is a recap of an older blogpost of mine. I decided to rewrite it after I wanted to refer a friend to it, and I saw the blogpost clearly failed a bit in getting the point across. In this blogpost, I hope to correct that. It’s about a situation in which Monads fall short, but Arrows (and Applicative) prove to be very
Many parser combinator libraries in Haskell (such as parsec) have both a Monad interface as well as an Applicative interface. (Actually, to be really useful, you also need MonadPlus along with Monad, or Alternative along with Applicative, in order to encode choice; from now on when I talk about Monad and Applicative note that I really have MonadPlus or Alternative in mind as well.) The Applicative
By Brent Yorgey, byorgey@gmail.com Originally published 12 March 2009 in issue 13 of the Monad.Reader. Ported to the Haskell wiki in November 2011 by Geheimdienst. This is now the official version of the Typeclassopedia and supersedes the version published in the Monad.Reader. Please help update and extend it by editing it yourself or by leaving comments, suggestions, and questions on the talk pag
please won't you tell me who is she? The Strathclyde Haskell Enhancement is an experimental preprocessor for the Glasgow Haskell Compiler, concocted hastily by Conor McBride at the University of Strathclyde. Its current functionality includes types indexed by data pi types pattern synonyms — definitions you can use on left and right support for a crude kind of aspect-oriented programming idiom bra
この記事は、Monad でつまづいた Haskeller のための Monad 再入門です。 Monadとは何ですか? Monad とは、単なる型クラスの一つです。難しいという風評もありますが、それ以上でもそれ以下でもありません。 この型クラスのメソッドは、return と >>= です。 class Monad m where (>>=) :: m a -> (a -> m b) -> m b return :: a -> m a つまり、以下を満たす型の集合が Monad です。 m a で表現できるように一つの型変数を格納するコンテナ型 >>= と return を実装 return は新しいコンテナを作り、>>= は二つのコンテナを合成します。 Monad のインスタンスは失敗系と状態系に大別できます。以下に代表的なインスタンスを示します。 失敗系: Maybe、[] (リスト)
@tanakh 師と @nushio による会話を横からメモしたもの。 - Haskellではエラーは型に追い出すのが正攻法。Pureな計算からErrorが飛び出てくるのは対処しようがないので避けるべき。 - 型に追いだすと最終的にすべての操作が例えばMonadの中で行われることになる。それをどう考えるか。 続きを読む
この記事の目的は、Applicative 信者による Applicative スタイルの布教です。 簡潔に結論を述べると、 foo = do a <- m1 b <- m2 return (f a b) のようなコードを書きたくなったら foo = f <$> m1 <*> m2 と書きましょうということ。 合い言葉は、「do と return をなくせ!」です。 FunctorとMonadの間 Functor を特殊化した型クラスがMonadで、Monadの方が強力です。なぜなら、メソッドが増えるからです。 Functorのメソッドはfmapです。fmapの別名を (<$>) といいます。(この記事では、(<$>) と liftM を同一視します。) そして、Monadのメソッドは、ご存知の通り (>>=) と return です。 FunctorとMonadの間にApplicative
Applicative よりも Monad の方が力が強い理由を考えるためのメモ。これから議論するためのたたき台なので、そう思って読んで欲しい。 コンテナで包む return Monad とは、コンテナである。コンテナは、文脈を表す。たとえば、Maybe というコンテナは、失敗するかもしれない計算という文脈を表す。 通常の値や関数を文脈に入れるための API が return である。 return :: a -> ma コンテナ内での関数適用 <*> 以下のような型を持つ関数を考える。 f :: a -> b この関数を return を使って文脈の中に入れてやると、型は次のようになる。 return f :: m (a -> b) この関数を、コンテナ内にある値に適応するための API が (<*>) である。 (<*>) :: m (a -> b) -> m a -> m b コンテ
Parsec には以下のようなコンビネーターが存在する。 many p -- p を 0 回以上 many1 p -- p を 1 回以上 count n p -- p を n 回 しかし、正規表現の"{min,max}"のような範囲指定はない。そこで実装してみた。 import ApplicativeParsec range :: Int -> Int -> GenParser tok st a -> GenParser tok st [a] range n m p = (++) <$> count n p <*> upto (m - n) p upto :: Int -> GenParser tok st a -> GenParser tok st [a] upto 0 _ = return [] upto n p = (:) <$> p <*> upto (n - 1) p <|>
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く