Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
brap
Aug 23, 2004

Grimey Drawer

Bloody posted:

What's a monad?

I'm sorry for being another person to talk about this.

A monad is when you put a wrapper around a value and make it so it's only possible to access that value with a callback. It's an extremely simple and general concept when you get to the heart of it. Ever use Nullable<T> in C#? Consider an example like this:

code:
Nullable<int> nullable1 = 4;
Nullable<int> nullable2 = null;

var result1 = nullable1 + 2; // Returns a nullable containing the value 6.
var result2 = nullable2 + 2; // Since this nullable contained a null, this operation returns null.
For result1 and result2, C# is automagically providing a function to the Nullable<int> which, given an int, returns that int plus 2. The nullable monad decides whether or not to make use of the function, depending on whether or not it has a value to provide to the function!

There's a zillion uses of this pattern that will make your programming life better. Look at all the LINQ stuff, Task<T>, Func<T>, etc. if you're in the .NET world.

Adbot
ADBOT LOVES YOU

brap
Aug 23, 2004

Grimey Drawer
I spent a lot of time with How to Design Programs in supplement to my regular college programming classes and it was incredibly helpful. It's what I recommend to everyone starting. It really strips away the stuff beginners should not be worrying about and helps beginners build good habits.

I haven't worked with the scheme book people mention often in the same breath but I'm sure it's good too.

brap
Aug 23, 2004

Grimey Drawer
I really think whoever devised the wikipedia definition of monad should be shot.

Math articles on Wikipedia in general are impenetrable gibberish.

brap
Aug 23, 2004

Grimey Drawer
Seriously, IO and effects and stuff has nothing to do with the definition of a monad. Set that aside when you first learn about them and try playing with a conceptually simple monad instance like Maybe.

  • Locked thread