<story><title>Haskell Concepts in One Sentence</title><url>https://torchhound.github.io/posts/haskellOneSentence.html</url></story><parent_chain><item><author>kaoD</author><text>The article is spot on. The problem with monads is not the what, is the why. Tutorials often explain the what, which is easy to understand (except where people get creative with similes... &amp;quot;monads are like tuna sausages, but you can build castles with them&amp;quot;).&lt;p&gt;Not having used them, I&amp;#x27;m still puzzled at _why_ I would need monads at all.&lt;p&gt;At this point, tutorials use examples like &amp;quot;like flatMap and Maybe in other languages!&amp;quot; which is even more confusing. Why do I need a monad then, if there are similar constructs in other languages that don&amp;#x27;t need the understanding of monad? Why the complexity? What do I get from monads?</text></item><item><author>jodooshi</author><text>&amp;gt; monads aren’t actually all that complicated. In fact, most of the experienced functional programmers I’ve met consider them downright simple. It’s just that newcomers often have a really hard time trying to figure out what exactly monads even are... A lot of intermediate-to-advanced functional programmers have taken it upon themselves to write monad tutorials... But for the most part, these tutorials never seem to work.&lt;p&gt;Why is that? Locked doors, headaches, and intellectual need: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;mkremins.github.io&amp;#x2F;blog&amp;#x2F;doors-headaches-intellectual-need&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;mkremins.github.io&amp;#x2F;blog&amp;#x2F;doors-headaches-intellectual...&lt;/a&gt; :-)</text></item><item><author>scottmsul</author><text>A monad is any data structure which implements bind. Bind is a higher-order function with two parameters - one is the data structure to be transformed, the other is a function which maps over elements in the data structure. However, unlike a normal map, each result of &amp;quot;bind&amp;quot; sits in its own version of the original data structure, which then have to be combined back into a single data structure. The way in which the data structures are combined is what makes each monad different.&lt;p&gt;For example, List is a monad. Suppose we had a List of Ints, such as [5,3,4]. If we were to run bind over this list, we would need a function that takes an Int and returns a List of something. We could use &amp;quot;show&amp;quot;, the function which converts Ints to Strings (a String is technically a List of Char. Since this is a List, we&amp;#x27;re good). If we call bind using [5,3,4] and show, we get [&amp;quot;5&amp;quot;,&amp;quot;3&amp;quot;,&amp;quot;4&amp;quot;] which are then combined to &amp;quot;534&amp;quot;.&lt;p&gt;We can check with the interpreter (&amp;gt;&amp;gt;= is bind):&lt;p&gt;Prelude&amp;gt; [5,3,4] &amp;gt;&amp;gt;= show&lt;p&gt;&amp;quot;534&amp;quot;</text></item></parent_chain><comment><author>beala</author><text>Monad, like any interface, is useful because we can abstract over it. Let&amp;#x27;s take an example from Java: both ArrayList and LinkedList implement List. This means I can write code that is agnostic to the implementation of List, and later I can drop in any implementation I want. Seen from the other direction: if I write something that resembles a list and I implement the List interface, all of the code that&amp;#x27;s compatible with List will also be compatible with my new implementation.&lt;p&gt;Similarly, if I define a new data type, and realize that it can implement Monad (or more precisely: that it has a monad instance), then I&amp;#x27;ll be rewarded with a giant library of code that&amp;#x27;s already compatible with my new data type [1]. Monad is an especially interesting interface because (1) it turns out many things conform to it [2] and (2) it comes with a set of algebraic laws. There is some controversy over how strict we need to be about the algebraic laws, but in some sense the algebraic laws are part of why such a general interface can be meaningful at all.&lt;p&gt;So yes, it&amp;#x27;s true that Monad allows us to sequence effects in a lazy pure language, and that&amp;#x27;s important, but I think a more down to earth reason to be interested is that it allows for more code reuse [3].&lt;p&gt;[1] Some of the function defined in the standard library: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;hackage.haskell.org&amp;#x2F;package&amp;#x2F;base-4.9.1.0&amp;#x2F;docs&amp;#x2F;Control-Monad.html#g:4&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;hackage.haskell.org&amp;#x2F;package&amp;#x2F;base-4.9.1.0&amp;#x2F;docs&amp;#x2F;Contro...&lt;/a&gt;&lt;p&gt;[2] See the &amp;#x27;instances&amp;#x27; section here: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;hackage.haskell.org&amp;#x2F;package&amp;#x2F;base-4.9.1.0&amp;#x2F;docs&amp;#x2F;Control-Monad.html#t:Monad&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;hackage.haskell.org&amp;#x2F;package&amp;#x2F;base-4.9.1.0&amp;#x2F;docs&amp;#x2F;Contro...&lt;/a&gt; These are just the instances in the standard library.&lt;p&gt;[3] It&amp;#x27;s also worth mentioning that Monad gets all the attention, but Haskell if flush with other mathematically inspired interfaces that are just as general.</text></comment>
<story><title>Haskell Concepts in One Sentence</title><url>https://torchhound.github.io/posts/haskellOneSentence.html</url></story><parent_chain><item><author>kaoD</author><text>The article is spot on. The problem with monads is not the what, is the why. Tutorials often explain the what, which is easy to understand (except where people get creative with similes... &amp;quot;monads are like tuna sausages, but you can build castles with them&amp;quot;).&lt;p&gt;Not having used them, I&amp;#x27;m still puzzled at _why_ I would need monads at all.&lt;p&gt;At this point, tutorials use examples like &amp;quot;like flatMap and Maybe in other languages!&amp;quot; which is even more confusing. Why do I need a monad then, if there are similar constructs in other languages that don&amp;#x27;t need the understanding of monad? Why the complexity? What do I get from monads?</text></item><item><author>jodooshi</author><text>&amp;gt; monads aren’t actually all that complicated. In fact, most of the experienced functional programmers I’ve met consider them downright simple. It’s just that newcomers often have a really hard time trying to figure out what exactly monads even are... A lot of intermediate-to-advanced functional programmers have taken it upon themselves to write monad tutorials... But for the most part, these tutorials never seem to work.&lt;p&gt;Why is that? Locked doors, headaches, and intellectual need: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;mkremins.github.io&amp;#x2F;blog&amp;#x2F;doors-headaches-intellectual-need&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;mkremins.github.io&amp;#x2F;blog&amp;#x2F;doors-headaches-intellectual...&lt;/a&gt; :-)</text></item><item><author>scottmsul</author><text>A monad is any data structure which implements bind. Bind is a higher-order function with two parameters - one is the data structure to be transformed, the other is a function which maps over elements in the data structure. However, unlike a normal map, each result of &amp;quot;bind&amp;quot; sits in its own version of the original data structure, which then have to be combined back into a single data structure. The way in which the data structures are combined is what makes each monad different.&lt;p&gt;For example, List is a monad. Suppose we had a List of Ints, such as [5,3,4]. If we were to run bind over this list, we would need a function that takes an Int and returns a List of something. We could use &amp;quot;show&amp;quot;, the function which converts Ints to Strings (a String is technically a List of Char. Since this is a List, we&amp;#x27;re good). If we call bind using [5,3,4] and show, we get [&amp;quot;5&amp;quot;,&amp;quot;3&amp;quot;,&amp;quot;4&amp;quot;] which are then combined to &amp;quot;534&amp;quot;.&lt;p&gt;We can check with the interpreter (&amp;gt;&amp;gt;= is bind):&lt;p&gt;Prelude&amp;gt; [5,3,4] &amp;gt;&amp;gt;= show&lt;p&gt;&amp;quot;534&amp;quot;</text></item></parent_chain><comment><author>eastWestMath</author><text>&amp;gt;At this point, tutorials use examples like &amp;quot;like flatMap and Maybe in other languages!&amp;quot; which is even more confusing. Why do I need a monad then, if there are similar constructs in other languages that don&amp;#x27;t need the understanding of monad? Why the complexity? What do I get from monads?&lt;p&gt;Monads are a mathematical concept, like a ring. &amp;quot;Maybe&amp;quot; is a monad in whatever language you use it in, just like integers are a ring in whatever language you use them in. Pointing out that complex numbers, rational numbers, nxn matrices are all examples of rings and wrapping everything up into a type class doesn&amp;#x27;t add to the complexity of the language.</text></comment>