June 19, 2014
On Thursday, 19 June 2014 at 03:10:50 UTC, logicchains wrote:
> Somebody should blog on this or put it on the front page or something; how many other languages allow a cost-free maybe monad to be implemented in library code?

I agree. This is supercool!
June 19, 2014
On 2014-06-18 17:46, Kapps wrote:

> C# is getting the same syntax, and I remember there being some
> discussion about it here. It's somewhat useful I suppose, though I think
> it's made significantly more useful in C# with 'a ?? b' (a if a is not
> null, else b).

And "a ??= b", assigne "b" to "a", only if "a" is null.

-- 
/Jacob Carlborg
June 19, 2014
> 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

Yes, it's more like a failsafe than a maybe. failsafe(c).left.right ...
June 19, 2014
Etienne:

> Yes, it's more like a failsafe than a maybe. failsafe(c).left.right ...

I suggest to not call it Maybe/maybe to not confuse it with the Haskell ones.

Bye,
bearophile
June 19, 2014
On 18/06/2014 21:20, "Ola Fosheim Grøstad" <ola.fosheim.grostad+dlang@gmail.com>" wrote:
> On Wednesday, 18 June 2014 at 15:42:04 UTC, Etienne wrote:
>>
>> writeln(obj.member?.nested?.val);
>>
>
> Optional chaining in swift is meant to be used more like this:
>
> if let v = ptr?.attr?.getobj?()?.attr? {
>    writeln(v)
> } else {
>    writeln("oops?!")
> }
>
> (I don't think Maybe will look as good.)

Perhaps Maybe could implement opCast!bool, then we could do:

if (auto v = ...)
June 19, 2014
On 2014-06-19 7:31 AM, Nick Treleaven wrote:
> Perhaps Maybe could implement opCast!bool, then we could do:
>
> if (auto v = ...)

That would be amazing, but maybe is used in haskell for a different purpose, so failsafe could be a more appropriate name I think:


if (auto k = tree.failsafe.left && auto v = tree.failsafe.right.leftArr.front.rightMap[k].left)
{
	...
}

Would be great
June 19, 2014
On Thursday, 19 June 2014 at 10:10:30 UTC, Jacob Carlborg wrote:
> On 2014-06-18 17:46, Kapps wrote:
>
>> C# is getting the same syntax, and I remember there being some
>> discussion about it here. It's somewhat useful I suppose, though I think
>> it's made significantly more useful in C# with 'a ?? b' (a if a is not
>> null, else b).
>
> And "a ??= b", assigne "b" to "a", only if "a" is null.

Is this any better than?

if(!a) a = b;
June 19, 2014
On Thu, Jun 19, 2014 at 09:15:47AM -0400, Etienne via Digitalmars-d wrote:
> On 2014-06-19 7:31 AM, Nick Treleaven wrote:
> >Perhaps Maybe could implement opCast!bool, then we could do:
> >
> >if (auto v = ...)
> 
> That would be amazing, but maybe is used in haskell for a different purpose, so failsafe could be a more appropriate name I think:
[...]

I've been thinking about the name. I realize that it's not a true monad in the Haskell sense, even though the implementation *was* inspired by deadalnix's mentioning of the Maybe monad, so we really should call it something else.  "failsafe" sounds a bit too generic. What about "safeDeref" or just "deref"?

OTOH, I wonder how easy it would be to refine the current implementation to become a true monad?


T

-- 
What is Matter, what is Mind? Never Mind, it doesn't Matter.
June 19, 2014
> I've been thinking about the name. I realize that it's not a true monad
> in the Haskell sense, even though the implementation *was* inspired by
> deadalnix's mentioning of the Maybe monad, so we really should call it
> something else.  "failsafe" sounds a bit too generic. What about
> "safeDeref" or just "deref"?
>
> OTOH, I wonder how easy it would be to refine the current implementation
> to become a true monad?
>
>
> T
>

ValueType!T / valueType(t) maybe? Its only purpose is to treat ref types as value types in a cascading way without restriction even when they're null... No idea how it could become a monad.
June 19, 2014
On 19/06/2014 16:04, H. S. Teoh via Digitalmars-d wrote:
> we really should call it
> something else.  "failsafe" sounds a bit too generic. What about
> "safeDeref" or just "deref"?

fallback? It could have an optional argument to override init.