On 06/18/2014 09:36 PM, H. S. Teoh via Digitalmars-d wrote:
Here's a first stab at a library solution:
/**
* Simple-minded implementation of a Maybe monad.
*
Nitpick: Please do not call it a 'Maybe monad'.
It is not a monad: It's neither a functor not does it have a μ operator.
(This could be fixed though.) Furthermore, opDispatch does not behave
analogously to a (restricted) monadic bind operator:
class C{ auto foo=maybe(C.init); }
void main(){
import std.stdio;
C c=new C;
writeln(maybe(c).foo); // Maybe(Maybe(null))
}
The result should be Maybe(null), if the data type was to remotely
resemble a monad.
Furthermore, 'Maybe' is a more natural name for a type constructor that
adds an additional element to another type, and 'Maybe monad' in
particular is a term that already refers to this different meaning even
more strongly in other communities.