Does each method return an "this" monad?

Is every class method that returns a thismonad?

+5
source share
4 answers

I'm going to say a very careful "maybe." A lot of this depends on your definitions.

It is worth noting that I take the definition of a monad from the theory of category theory , and not the construction of functional programming .

If you are thinking of a Aclass method Cthat maps an instance Cto another instance C(i.e. returns this), then it will look like it C.A()is a functor from a category consisting of Cinstances for itself. Therefore, at least it is an endosensor. It seems that this construction corresponds to the basic properties of identity and associativity that we expect, but further verification should say for sure.

In any case, I would not put my life on this, and I'm not sure that this is a very useful way to think about such constructions, but at least it seems like a reasonable assumption during the first check.

+7
source

. , ( , ), return this; ( , monads imho , , option).

, , "":

, ( ) M [... , ]

Edit: , - , (, ). : " , this?" </nitpick>

+4

, , , .

. , this, - endo , .

, , , , , F(A) => (A -> A) , , , .. A -> B A -> A A -> B, B -> B A -> B, B -> B A -> A .


. , this . , C C . . , - , ! , C C:

  • , A A -> B, , - B: , aka 'fmap` Haskell.

  • A, , : monad "unit", a.k.a. return Haskell.

  • , A, A B, , B . , a.k.a. (>>=) Haskell.

Haskell ", ", "Reader Monad" do , , - , this .

, ... , , , , .

+4

-, No.

, .

  • . A , B (, , A B, ).
  • , . , A TypeX, B TypeY, , Monad (TypeX) Monad (TypeY). , Monad (TypeX), Monad (TypeY), TypeY B.

, , Fluent Interface. , , , , , , , , ( ,., - do), . , , .

2: : a) TypeX Monad (TypeX), Monad (TypeX) Monad (TypeY) Monad (TypeY) TypeY

+1

All Articles