Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is every method returning `this` a monad?

Is every method on a class which returns this a monad?

like image 235
Krabbe Avatar asked Aug 19 '10 19:08

Krabbe


1 Answers

I'm going to say a very cautious "possibly". A lot of this is contingent on your definitions.

It's worth noting that I'm taking the definition of monad from the category theory construct, not the functional programming construct.

If you think of a method A of class C that maps a C instance to another C instance (i.e. it returns this), then this would appear that C.A() is a functor from the category consisting of C instantiations to itself. Therefore it's an endofunctor, at least. It would appear that this construction obeys the basic identity and associativity properties that we expect, but further inspection would be required to say for sure.

Anyway, I wouldn't stake my life on it, and I'm not certain this is a very helpful way about thinking of such constructions, but it does seem a reasonable assumption on first inspection, at least.

like image 119
Gian Avatar answered Oct 05 '22 12:10

Gian