Maybe Monad

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Maybe Monad

horrido
Is there a Pharo equivalent to Ruby's Maybe monad? See
https://github.com/rap1ds/ruby-possibly




--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Reply | Threaded
Open this post in threaded view
|

Re: Maybe Monad

Ben Coman
On 27 January 2018 at 08:33, horrido <[hidden email]> wrote:
> Is there a Pharo equivalent to Ruby's Maybe monad? See
> https://github.com/rap1ds/ruby-possibly

From that page I read...
   "Maybe monad is a programming pattern that allows to treat nil
values that same way as non-nil values"

At a minimum you can just define required methods on UndefinedObject.
For example...
    UndefinedObject >> myThing
           self inform: 'Nil does my thing!!'

then in Playground evaluate...
    nil myThing

This obviously doesn't cover the "Some" part of Maybe-monad,
but you didn't provide any description of what you're trying to do so
I don't know how important that is to you.

However, in general a better approach than adding methods to
UndefinedObject if to use the Null pattern.
Initialize your variables with an instance of MyDomainNull which
defines the minimum required messages to avoid DNUs.
Such a class might fit as the root superclass of all your domain classes.
But this suggestion might be off target, since I can't grok where I'd
use something like Maybe-Monad in my own programming.

cheers -ben

Reply | Threaded
Open this post in threaded view
|

Re: Maybe Monad

gcotelli
In reply to this post by horrido
There is something similar in GitHub.com/ba-st/Buoy called Optional. It's not a full fledged Monad implementation but for most cases it would do.

On Jan 26, 2018 21:34, "horrido" <[hidden email]> wrote:
Is there a Pharo equivalent to Ruby's Maybe monad? See
https://github.com/rap1ds/ruby-possibly




--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html