Monads are actually a very simple concept. They're really hard to understand at first because of how much knowledge is prerequisite. I found that by teaching myself Haskell incrementally, in small steps, I was able to understand monads just as easily as anything else. For me, it was simply resolving the following dependency graph: Algebraic data types -> type classes -> functors -> applicative functors -> monoids ->…
Monads explained by Eric Lippert
21–30 of 58 posts
Re: Monads explained by Eric Lippert
#22Why do you need to understand monads? Nobody explains groups to people using integers, either.
Re: Monads explained by Eric Lippert
#23Why do you need to understand monads? Nobody explains groups to people using integers, either.
Instead, I explained that "functions" in Haskell are deterministic and that "procedures" have a different type from functions. From there it was pretty easy to add that there are also types that represent more-restricted kinds of procedures that only have access to a limited set of effects. If he ever decides to take the plunge and actually learn some Haskell, I'll connect the idea up to the Monad class as "the minimal interface common to all procedure types", with emphasis on the idea that it's just the minimal API necessary to make something like "do" notation work.
That is really all a user needs to know about monads to get started with using them. Of course they need more if they'd like to implement their own, but by the time they're thinking along those lines most people will have already learned enough about them from osmosis since, as other people have remarked, it's not a hard concept - it just has a lot of prerequisites. Even then, though, most of what most users want is well enough served by a similarly shallow understanding of monad transformers (they add features to procedure types, etc.)
Re: Monads explained by Eric Lippert
#24Do you know what I miss about these explanations? Technical people can't go straight to the point. They go around, around, around, going into corners, etc (not only on explanations, mind you) For example, math has some very high-level/generic explanations, and curiously, I find them more understandable. So, I've given up on understanding Monads (or at least Haskell ones), I'll probably understand them when I come up…
Re: Monads explained by Eric Lippert
#25Monads should be a familiar concept for the seasoned C# programmer. LINQ's 'from in' syntax and the haskell monad 'do' syntax are almost the same! Heck, the type signature of SelectMany and (>>=) are even the same! (>>=) :: m a -> (a -> m b) -> m b and public static IEnumerable SelectMany ( this IEnumerable source, Func > selector ) m = IEnumerable b = TResult a = TSource => m SelectMany (this m source, Func > select…
Re: Monads explained by Eric Lippert
#26Monads should be a familiar concept for the seasoned C# programmer. LINQ's 'from in' syntax and the haskell monad 'do' syntax are almost the same! Heck, the type signature of SelectMany and (>>=) are even the same! (>>=) :: m a -> (a -> m b) -> m b and public static IEnumerable SelectMany ( this IEnumerable source, Func > selector ) m = IEnumerable b = TResult a = TSource => m SelectMany (this m source, Func > select…
I once copied the style of a maybe monad using LINQ - the WinRT apis lack a "FileExists?" method, so I used LINQ to search a directory's contents for a filename. An IEnumerable of size of zero represented None, and size one represented Some.
Unfortunately, a simple try/catch around an attempt to open the desired file was more efficient and clearer to understand.
Re: Monads explained by Eric Lippert
#27Re: Monads explained by Eric Lippert
#28Why do you need to understand monads? Nobody explains groups to people using integers, either.
You've never been curious about something you don't know about, but don't immediately need?
IMO there's nothing wrong with more, but the fact that there are so many out there seems to perpetuate the incorrect belief that it's something you need to learn to actually use Haskell. I suspect that the GP was addressing this belief, not saying "nobody should bother learning this stuff".
Re: Monads explained by Eric Lippert
#29Monads should be a familiar concept for the seasoned C# programmer. LINQ's 'from in' syntax and the haskell monad 'do' syntax are almost the same! Heck, the type signature of SelectMany and (>>=) are even the same! (>>=) :: m a -> (a -> m b) -> m b and public static IEnumerable SelectMany ( this IEnumerable source, Func > selector ) m = IEnumerable b = TResult a = TSource => m SelectMany (this m source, Func > select…
Further proof for my personal conviction that C# is a very interesting, progressive language which masquerades as a Java clone. I once copied the style of a maybe monad using LINQ - the WinRT apis lack a "FileExists?" method, so I used LINQ to search a directory's contents for a filename. An IEnumerable of size of zero represented None, and size one represented Some. Unfortunately, a simple try/catch around an attemp…
Re: Monads explained by Eric Lippert
#30The monad is the clitoris of programming.