Talk:Monad (functional programming): Difference between revisions

Content deleted Content added
Readability/Understandability?: see Wikibooks/Haskell wiki
First paragraph needs a lot of help for first-timers. There's too much jargon and unspecified syntax.
 
(355 intermediate revisions by 92 users not shown)
Line 1:
{{Talk header}}
{{WikiProject Computer science}}
{{WikiProject banner shell| class=C |
{{WikiProject Computer science|importance=mid}}
{{WikiProject Computing|importance=low}}
}}
{{FAQ}}
{{To do|collapsed=yes}}
{{Archives|auto=yes|search=yes}}
 
== Informal style ==
 
Occasionally I'm seeing sentences that read more like a blog post than an encyclopedia:
== Merging articles and the name of the article ==
 
<blockquote>
This is actually the same as [[Monad (category theory)]]. These should be merged. &mdash;[[User:Ashley Y|Ashley Y]] 22:19, 2004 May 31 (UTC)
With just a little extra functional spice on top, this Maybe type transforms into a fully-featured monad.
 
Having to rewrite functions to take Maybes in this concrete example requires a lot of boilerplate (look at all those Just expressions!).
:They're not really the same thing: an explanation of Haskell's IO monad doesn't belong in an article on category theory, and a detailed explanation of monads in category theory isn't relavent to the average Haskell programmer. In addition, many standard Haskell monads aren't strictly speaking monads at all. I think it's probably best to keep the articles separate. [[User:Cadr|Cadr]] 22:28, 31 May 2004 (UTC)
</blockquote>
 
I'm not up on the latest Wikipedia guidelines, so I'm not confident about what is allowed. I'm curious about what the current thinking is from anyone who knows more about this topic. [[User:Modify|modify]] 15:16, 29 August 2022 (UTC)
::Which Haskell monads are not monads in the CT sense? &mdash;[[User:Ashley Y|Ashley Y]] 09:58, 2004 Jun 1 (UTC)
 
:This article indeed seems to get consistently edited towards a semi-formal programming how-to style, against [[Wikipedia:NOTHOWTO]]. I have already posted a template noting this once to little effect. [[User:Terminator 2 really happened|Terminator 2 really happened]] ([[User talk:Terminator 2 really happened|talk]]) 19:26, 8 August 2024 (UTC)
:::The IO monad is one example (see [http://www.haskell.org/pipermail/haskell/2002-May/009622.html]). [[User:Cadr|Cadr]] 11:08, 1 Jun 2004 (UTC)
 
== Pseudo-code in the article ==
::::It's not clear, actually, since the difference is only visible with the 'seq' function, which is considered slightly dubious anyway. More importantly, these are ''Haskell's'' monad laws that IO may or may not be properly living up to: the sense in which "monad" is used in Haskell is ''precisely'' the CT sense.
 
The meaning of [https://en.wikipedia.org/w/index.php?title=Monad_(functional_programming)&curid=579061&diff=1118556608&oldid=1118549561 the pseudo-code] needs to be clarified:
::::If you think this should be a separate article, rename it "Monads in functional programming", rather than the () notation which suggests that it's a separate sense of the word.&mdash;[[User:Ashley Y|Ashley Y]] 02:49, 2004 Jun 2 (UTC)
: (f >=> g) x = (f(x) → mb) >>= g(y = b)
 
:1: My personal reading is that this is an equation. The left hand side is <code>(f >=> g) x </code>
:::::OK, but it's still the case that the two articles cover very different information. I'm fine with it being renamed to Monads in functional programming. [[User:Cadr|Cadr]] 14:15, 2 Jun 2004 (UTC)
:2: The right hand side is
::'''Let''' functor <code>(f(x) → mb)</code> '''be''' the functor resulting from substituting mb for y in g;
:3: The (y=b) on the right hand side is not an equation; but g(y=b) is an application of g to the type y where b
:4: The f → mb is a functor from type x to monadic value mb where b
{{anchor|klComposeOper}}The Kleisli compose operator <code>>=></code> means if some m >>= f then f is the continuation of m.<ref name= gg >[https://www.haskellforall.com/2012/12/the-continuation-monad.html? showComment=1424959716748#c3272667111873173855 Memetic Warrior (26 Feb 2015) reply to] [https://www.haskellforall.com/2012/12/the-continuation-monad.html? Gabriel Gonzalez, Haskell for All (30 Dec 2012) The Continuation Monad] </ref>
-- [[User:Ancheta Wis|Ancheta Wis]] [[User talk:Ancheta Wis| &nbsp; (talk]] [[Special:Contributions/Ancheta Wis| &#124; contribs)]] 18:59, 27 October 2022 (UTC), 01:42, 28 October 2022 (UTC)
 
{{anchor|akContin}}Alexis King<ref name=alexisKing >[https://github.com/lexi-lambda Alexis King, github]</ref> notes that if m >>= f >>= g >>= h then the continuation of m is f >=> g >=> h <ref name= lexiLambda >[https://gist.github.com/lexi-lambda/d97b8187a9b63619af29689e9fa1b880 lexi-lambda/continuations-and-reduction-semantics.md]</ref> --[[User:Ancheta Wis|Ancheta Wis]] [[User talk:Ancheta Wis| &nbsp; (talk]] [[Special:Contributions/Ancheta Wis| &#124; contribs)]] 19:18, 27 October 2022 (UTC)
Rename (from "[[Monad (functional programming)]]") done. &mdash;[[User:Ashley Y|Ashley Y]] 23:27, 2004 Jun 2 (UTC)
{{talkref}}
 
: The notation doesn't make much sense and seems to have been introduced quite randomly and without references in https://en.wikipedia.org/w/index.php?title=Monad_(functional_programming)&diff=next&oldid=867467071 , along with a few other strange changes by [[user:Zar2gar1]] in the vicinity. To me, [[user:Nbrader]]'s edit is a correction. --[[User:Daniel5Ko|Daniel5Ko]] ([[User talk:Daniel5Ko|talk]]) 23:27, 28 October 2022 (UTC)
Er, the first sentence of the second para (and possibly more) looks like a copyvio from http://nomaware.com/monads/html/introduction.html#what --- I don't know the topic well enough to rephrase to eliminate this. Could someone who knows the topic look into this? thanks, [[User:JosephBarillari|jdb &#x274b;]] 06:00, 27 Jan 2005 (UTC)
::So which is it,
:::(f >=> g) x = (f x) >>= g
:::or some other parenthesization needed?
:::(f >=> g) x = f x >>= g
:::ping [[user:Zar2gar1]] --[[User:Ancheta Wis|Ancheta Wis]] [[User talk:Ancheta Wis| &nbsp; (talk]] [[Special:Contributions/Ancheta Wis| &#124; contribs)]] 00:14, 29 October 2022 (UTC)
 
@[[user:Zar2gar1]], Thank you for your pseudocode in the article, which attempts to accomodate the requests of the readership to avoid Haskell. Because of the objections above, I propose the use of Bartosz Milewski's 2019 book ''Category Theory for Programmers'' pages 202 through 205, which uses Haskell notation to explain Kleisli composition <code>>=></code> . Dr. Milewski uses Kleisli composition <code>>=></code> and <code>return</code> to implement Monad. In fact Dr. Milewski implements Monad in Haskell three ways on those pages. --[[User:Ancheta Wis|Ancheta Wis]] [[User talk:Ancheta Wis| &nbsp; (talk]] [[Special:Contributions/Ancheta Wis| &#124; contribs)]] 01:08, 29 October 2022 (UTC)
== par function ==
 
: @"which is it": The two alternatives have the same meaning. Even more: They already have identical parse trees. --[[User:Daniel5Ko|Daniel5Ko]] ([[User talk:Daniel5Ko|talk]]) 00:40, 30 October 2022 (UTC)
Why is the function <math>(x, y) \mapsto \frac{1}{\frac{1}{x}+\frac{1}{y}}</math> called par? --[[User:MarSch|MarSch]] 11:06, 25 October 2005 (UTC)
 
:: Firstly, sorry for replacing the pseudo-code with Haskell code without reading the talk page first: I didn't realize there was an effort to avoid Haskell code. I will say though I found the pseudo-code confusing. My feeling (for what it's worth) is that psuedo-code that has no clear meaning to most people defeats the point of pseudo-code and you're better off going with an actual language like Haskell. [[User:Nbrader|Nbrader]] ([[User talk:Nbrader|talk]]) 01:21, 30 October 2022 (UTC)
: At least that's the function for total resistance of two resistors in [[Series and parallel circuits|'''par'''allel coupling]]. --[[User:TuukkaH|TuukkaH]] 16:14, 25 October 2005 (UTC)
 
The equation "(f >=> g) x = (f(x) → mb) >>= g(y = b)" is very confusing, it's unclear where mb and y are bound; I have never seen anything similar. The explanation in this thread is also misguided: x is not a type and there is no substitution happening that forms functors.
For people used to reading C++ all day, "//" is a very difficult operator name to read. It looks like the start of a comment, and it's almost painful to have to ignore such "comments". Perhaps it could be renamed to "./." or even "///"?
[[User:Kimbly|Kimbly]] 02:52, 10 January 2006 (UTC)
 
It makes sense to avoid Haskell-specific notation, but here the only notation used is function application written as "f x", and binary operator "f >=> g". I restored the equation, using f(x) as function application. That should be understandable without additional prerequisites. [[Special:Contributions/2001:861:3F42:1B60:AEFC:B99:1842:A29E|2001:861:3F42:1B60:AEFC:B99:1842:A29E]] ([[User talk:2001:861:3F42:1B60:AEFC:B99:1842:A29E|talk]]) <!--Template:Undated--><small class="autosigned">—&nbsp;Preceding [[Wikipedia:Signatures|undated]] comment added 07:57, 24 November 2022 (UTC)</small> <!--Autosigned by SineBot-->
:What about "::", "->", and "--"? (and "|", ">>=", ">>" and "++", further down the page.) Like "//", they all have specific, and entirely different, meanings in C++. Beyond C++ and Haskell, you'll find yet other meanings for them. What makes C++'s "//" special enough to avoid?
:Besides, it's fairly clear that the examples are not in C++, so i don't see how it could cause more than momentary confusion, at worst. --[[User:Piet Delport|Piet Delport]] 04:34, 10 January 2006 (UTC)
 
:Hi everyone, I'm still going to be away from Wikipedia for the foreseeable future, but I did get the ping for this conversation. I'm going to try to keep my response simple. For the specific expression about monadic composition, just like you guessed @[[user:Ancheta Wis|Ancheta Wis]], the "g(y=b)" expression is a kludge to show variable binding and application in the few cases leaving them implicit is ambiguous. It's not the cleanest way for sure, but it does allow avoiding lambda calculus as a pre-req to understand the article.
:: In most grammars, comment signs are special: <code>//</code> and <code>/*</code> in C++, Java etc., <code>#</code> in Python etc., <code>;</code> in Lisp, <code>--</code> and <code>{-</code> in Haskell. I noticed I've special-cased them too and skip text in them automatically. C++ programmers are used to <code>&lt;&lt;</code> etc. meaning many things because they are overloaded already in the standard and most every language has [[operator overloading]]. Of course you can get accustomed to any a syntax, but do we want to make it as hard as possible for people to read this article? It's not like <code>//</code> would be an integral part of the Haskell syntax. --[[User:TuukkaH|TuukkaH]] 09:19, 10 January 2006 (UTC)
 
:Big picture, anyone that wants to think through & change the code has my full support. I left [[Talk:Monad_(functional_programming)/Archive_2|a lot of comments and notes in the Talk archives]] while finishing up my changes though. My main opinions are pretty much:
:::Personally, i've been using C, Java, and Javascript for at least a couple of years (with <code>//</code> comments wherever possible; i'm not fond of <code>/**/</code>), but the example still doesn't cause me any discomfort. Besides, even if you limit the symbols to comments, what about Forth (and Forth-like) programmers, who use parentheses for comments (like in English)? The curly brace programming languages are very important and influential, but they're not special enough to start imposing their syntactical meaning on innocent bystanders.
:* Avoid making mostly independent concepts like lambda calculus or currying pre-reqs to understand the article
:::Besides all that, i want to note that <code>//</code> already has an established meaning of "modified/alternate division" in several languages (including Python): something that thousands of people can recognize immediately. This alone should make it an obvious winner over inventions as novel as <code>///</code> and <code>./.</code>. --[[User:Piet Delport|Piet Delport]] 19:51, 10 January 2006 (UTC)
:* Try to be consistent and head-off misinterpretations around things like order of evaluation
:* The "right thing to do" would probably be to hash out functional pseudo-code guidelines for Wikipedia at large
:* Barring that, I do feel math-ish notation is preferable, followed by something like an established functional language (just looser & more accessible)
 
:I don't expect people to read my notes (they're long), but if you are willing to, you may still want to factor in my rationale at some points. [[User:Zar2gar1|Zar2gar1]] ([[User talk:Zar2gar1|talk]]) 05:49, 28 November 2022 (UTC)
:I know what you mean, I've had the same problem with people using <code>#</code> or <code>##</code> as an operator, while in Python, shell etc. they are used to start comments. As this page isn't strictly about Haskell, if we want to use Haskell as an example, we could still try to remove unnecessary readability problems from the article. --[[User:TuukkaH|TuukkaH]] 05:50, 10 January 2006 (UTC)
 
== Monad versus monoid ==
==Rewrite==
I guess my scam is up. I haven't really used Haskell any significant amount, and I barely understand this monad stuff. I just hoped I might be able to push this article away from the two mistakes so many monad tutorials make&mdash;presenting them as "how you do I/O" or completely neglecting to give any intuition to the general concept of a monad. I did my rewrite with a copy of Wadler's "Comprehending Monads" in hand, but since I made so many mistakes I'll tag the article for verification. TuukaH is correct above about the naming of <code>par</code>. [[User:Gazpacho|Gazpacho]] 04:13, 29 October 2005 (UTC)
 
Talk for [https://en.wikipedia.org/w/index.php?title=Monad_(functional_programming)&curid=579061&diff=1183880921&oldid=1183845787 BRD] -- [[User:Ancheta Wis|Ancheta Wis]] [[User talk:Ancheta Wis| &nbsp; (talk]] [[Special:Contributions/Ancheta Wis| &#124; contribs)]] 02:03, 7 November 2023 (UTC)
==Haskell==
 
== Permutation? ==
This page really seems to be more about monads in Haskell, rather than in a generic programming language. The examples given seem to be in Haskell, which for non haskell programmers (i.e. me) are really hard to follow.
 
It was added at https://en.wikipedia.org/w/index.php?diff=438062307 that the monoid being "non-commutative and idempotent" implies permutation. I think the property as described cannot mean "free and idempotent", as [a, b, a] wouldn't be called a permutation. Is there a way to clarify the property to really give permutations? Otherwise, is it even meaningful to name the collection type arising from free and idempotent monoid? [[User:J824h|Junghyeon Park]] ([[User talk:J824h|talk]]) 04:27, 11 December 2023 (UTC)
Shouldn't this either be renamed to something like "Monads in Haskell" with a link to understanding Haskell, or have the equations written in a common mathematical way?
 
:@[[User:J824h|J824h]]: Sorry it's almost a year later, but that was a really good catch. I reorganized that section into the table a few years back but didn't bother to think through the content enough.
:If I understand correctly, monads are containers for values: for example, a monad value like "Just 5" contains the value 5. The return function "wraps" a value inside a monad, the fmap function allows another function to "look inside" a monad value, and it looks like join turns a value like Just (Just 5) into Just 5, or <nowiki>[[3]]</nowiki> into [3]. A few examples:
:If you have idempotence but no commutativity to allow reduction, then I'd guess you have the most free regular language ''with no immediate repetitions'' over a given alphabet (of size ''N''). Which itself is isomorphic to the maximal, loop-free, digraph with ''N'' vertices (interpreted as a finite state machine over the alphabet)? Anyways, even if that's interesting, it doesn't strike me as particularly noteworthy or relevant to the article.
:I feel like the ability to generate permutations from a monoid is noteworthy though so I corrected the line. To distinguish from the free monoid, it explicitly says "[[partial permutation]]" now. And maybe it's a bit of hand-waving, but now it just describes the monoid as "non-commutative without repetition". Does that sound good? -- [[User:Zar2gar1|Zar2gar1]] ([[User talk:Zar2gar1|talk]]) 17:37, 21 November 2024 (UTC)
::@[[User:Zar2gar1|Zar2gar1]] That constraint on List should suffice to give "permutations". I wouldn't even call them "partial", as in the other rows not explicitly alluding to the relation to the underlying set or basis (like saying "subsets" for sets). I guess a permutation here should have implied an arrangement, not a mapping.
::Coming back to this, I wonder whether permutations have well-defined associative join from the first place. How do I define [a] ++ [b] ++ [a]? I might be missing something. [[User:J824h|Junghyeon Park]] ([[User talk:J824h|talk]]) 14:37, 27 November 2024 (UTC)
:::Right, I think what makes it tricky to describe these container monads is also why they're interesting. A monoid is typically described in algebraic or formal language terms, but when you apply the monad structure, you get these containers that feel more combinatoric.
:::I could be wrong, but my gut feeling is the original editor intended the idea of "without replacement" by listing "permutations". Definitely double-check me, but viewed as selections, ''ordered'' selections ''with'' replacement would yield a full permutation (which is effectively the free monoid), ''unordered'' selections ''with'' replacement would yield multisets, and ''unordered'' selections ''without'' replacement would yield sets?
:::The obvious 4th piece would be ''ordered'' selections ''without'' replacement, which I guess would technically be partial permutations? The symmetry is really easy to see combinatorically, but our current table lists the property of the monoid, which isn't nearly as elegant.
:::Per your specific question about a well-defined join, if I'm thinking through this right, both full and partial permutations would have a well-defined join ''on their respective domains''. In a full permutation, there's no restriction on the ___domain so the join yields [a,b,a] without any issues. For a partial permutation though, listing 'a' twice is prohibited at the monoid level so in your example, the ++ would yield a type error at the 2nd 'a' prior to any join. As long as nothing is repeated though, there's no reason the naive join wouldn't work just like with the full permutation / free monoid. -- [[User:Zar2gar1|Zar2gar1]] ([[User talk:Zar2gar1|talk]]) 19:11, 28 November 2024 (UTC)
::::[a, b] + [a] does need to be defined as long as both [a, b] and [a] are in the monad. To get permutations, we need a relation that identifies [a, b, a] to either [a, b] or [b, a], that is, a choice of left- or right-bias for each element. We don't have a unique but multiple valid concrete structures, which seems kind of unfortunate. Otherwise, we might simply accept [a, b, a] = error as a monadic value, which would be without a surjective homomorphism to sets and fit worse in the table. Do I make sense?
::::Regarding the whole table, I would see this table as a commutative diagram of "list → multiset → set", "list → permutation → set". The combinatoric interpretation is interesting. For the permutations, choosing universal left-bias might correspond to enforcing causality (the items selected earlier is removed from the pool and forbidden).
::::I don't think full permutation allowing duplicates is a standard terminology. Also, I stand by just permutation instead of partial permutation, as there is nothing to disambiguate in the context, and [[Partial permutation#Restricted partial permutations|being partial can mean many things]]! [[User:J824h|Junghyeon Park]] ([[User talk:J824h|talk]]) 15:18, 29 November 2024 (UTC)
 
{{outdent|4}} Ahhh, you're right, I totally forgot about the closure there. I also think you're exactly right about biasing the operator so that it's well-defined.
return 3 = either [3] or Just 3 -- "Wrap" the value 3 with a monad
fmap (+1) [3,2,4] = [4,3,5] -- (+1) is the incrementor function, and it is allowed to "peek inside" this list to increment everything inside it.
fmap (+1) (Just 5) = Just 6 -- Peeking inside a "Just" value.
join Maybe (Maybe 7) = Maybe 7 -- "Joining" these two Maybe's into one
join <nowiki>[[2]]</nowiki> = [2] -- Joining a listifier with a listifier
 
Because the join is a natural transformation, that would probably still remain naive, and the + would need to implement the bias. I would think either direction could work though; the append would just need to directly compare the items, then drop duplicates from either the left or the right. And like you said, you could interpret the left-bias causally like selection without replacement (and the right-bias is... anti-causal?)
:Is this clear enough? --[[User:67.172.99.160|67.172.99.160]] 02:09, 3 December 2005 (UTC)
 
''That said'', I also think you're right that we're getting into the weeds about the permutation bit. There's actually not even a citation either so while I think technical articles (especially hard topics) need some flexibility to work out the math / logic oneself, we're probably veering into [[WP:SYNTHESIS]] at this point.
::Kind of. Monads are types with associated functions (''bind'' (written ''>>='') and ''return''). These are sometimes containers in a naive way &mdash; the List monad and Maybe monad. But monads like CPS "contain" something, but it's not directly accessible in any way. More complicated monads do even crazier things: threaded coroutines can be expressed as a monad. Taking an example from a tutorial site (sorry, can't find the URL), a monad could keep a value corresponding to the remaining number of steps to allow in the computation; when this counter reaches zero, all binds just return the value computed up to that point. None of these are "containers for values" in any sensible way.
 
So I just cut any mention of the permutations from the table for now. I also consolidated the table layout a bit, but noted the combinatoric properties (so the potential symmetry I mentioned is still implied). If you think it needs more work though or that it should be cut, you should probably go for it. This article definitely needs more attention to the technical details. -- [[User:Zar2gar1|Zar2gar1]] ([[User talk:Zar2gar1|talk]]) 17:26, 3 December 2024 (UTC)
::I don't think moving to "Monads in Haskell" is appropriate. It begins by describing everything abstractly, but eventually we need to discuss monads in practice. Our choices are limited to Haskell, Clean, and Miranda<sup>TM</sup>. Every other programming page just picks a language, so why not here? If another language you know of uses monads in an interesting way and with a different syntax, by all means add it in!
 
:Leaving only the relatively obvious varieties makes sense. About the additional columns, I personally see them redundant but having both perhaps helps readers less familiar with algebraic terms. We should defer a potential improvement on this part to a separate discussion. Thanks for the discussion! [[User:J824h|Junghyeon Park]] ([[User talk:J824h|talk]]) 16:09, 4 December 2024 (UTC)
::I think the current explanation is fine. In that sense the "cite" tag is inappropriate, but it would be nice to cite some source on monads anyway. --[[User:Mgreenbe|Mgreenbe]] 10:00, 4 January 2006 (UTC)
::You're right, the new columns are redundant for anyone that knows the mathematical definitions or can understand the linked articles. But that can be a good thing for new readers.
::Thank you too for talking through it with me; it was kind of fun. Maybe I should get over my bad feelings from university and go back to grad school someday. -- [[User:Zar2gar1|Zar2gar1]] ([[User talk:Zar2gar1|talk]]) 02:39, 5 December 2024 (UTC)
 
== JustRust markup issueexample ==
 
Hi all. I would like to ask regarding the Rust example. It is written in [[Monad (functional programming)#An example: Maybe|Monad (functional programming)#An example: Maybe]] that the Rust example is using <code>Maybe</code>, <code>Just</code>, and <code>Nothing</code>, while Rust actually uses <code>Option</code>, <code>Some</code>, and <code>None</code> respectively [https://doc.rust-lang.org/std/option/]. Is this intended to be written this way? [[User:Mangkoran|Mangkoran]] ([[User talk:Mangkoran|talk]]) 11:19, 19 December 2023 (UTC)
The cleanup tag really only refers to the fact that the first line is not rendered as the following lines are, and despite my attempts to fix it, it stubbornly remained the same... perhaps this is trivial, but still visually not pleasing. <small>&mdash;''The preceding [[Wikipedia:Sign your posts on talk pages|unsigned]] comment was added by'' [[User:Laddiebuck|Laddiebuck]] ([[User talk:Laddiebuck|talk]]&nbsp;&bull;&nbsp;[[Special:Contributions/Laddiebuck|contribs]]) 02:52, March 2, 2006 (UTC).</small><!--Inserted with Template:Unsigned-->
 
:It is not claiming to be in std namespace. While it is probably influenced by the crate https://crates.io/crates/rsmonad, I'm not sure if it's worth mentioning since the API seems pretty generic. Would some clarification help maybe? [[User:J824h|Junghyeon Park]] ([[User talk:J824h|talk]]) 07:36, 19 January 2024 (UTC)
:The rendering is different because the line doesn't contain any non-standard characters, and is thus rendered in HTML instead of LaTeX. If you set your user preferences to "always render PNG", all lines will be the same. &mdash;<tt>[[User:donhalcon|donhalcon]]</tt><sup>[[User talk:donhalcon|╤]]</sup> 03:03, 2 March 2006 (UTC)
 
== Multiple major issues ==
:I have adjusted the markup to use &lt;code&gt; tags instead of &lt;math&gt; tags and HTML entities instead of PNGs. Should look ok now regardless of settings. &mdash;<tt>[[User:donhalcon|donhalcon]]</tt><sup>[[User talk:donhalcon|╤]]</sup> 03:34, 2 March 2006 (UTC)
 
This article reads as an informal guide for programmers, contrary to [[WP:NOTAGUIDE]]. Almost half of all sources are Internet postings, conference talks, and Haskell wiki pages and many, not limited to these types, are strongly opinionated or tutorial; following these, the text comes across as [[WP:OR]] outside a few more encyclopedic sections like History. Normative statements about usage should be contextualized as proper to the norms of functional programming, where they can be supported as such, and otherwise avoided as editorial. Lengthy segments are motivated by only appeals to naturalness, enumerations of supposed advantages, or assertions about what 'many programmers prefer', if at all, and sourced only to guides and documentation, if at all. In my view, major cuts and rewrites are required. Looking at how the subject is handled in other languages, I can recommend [https://de.wikipedia.org/wiki/Monade_(Informatik) the German article] as being a fraction of the length and proceeding from definitions to context to a focused set of examples. [[User:Terminator 2 really happened|Terminator 2 really happened]] ([[User talk:Terminator 2 really happened|talk]]) 22:06, 8 August 2024 (UTC)
== Monad and sequencing ==
 
:@[[User:Terminator 2 really happened|Terminator 2 really happened]]: I worked on this article a while back, and while I don't really plan to much more, I mostly agree with you. I think the one thing that keeps me checking back in is that I never redid the Continuation monad section. And it bugs me for some reason ([[call/cc]] is honestly still a riddle I haven't entirely wrapped my head around).
The article states that "Since the bind operator is non-associative, this constrains the sequence of execution." Is this really correct? The monad laws require that bind be associative, and the sequencing effect is due to the non-commutative properties of the bind operator. [[User:Chuan-kai Lin|Chuan-kai Lin]] 17:26, 3 April 2006 (UTC)
:If you're ready to prune the article, especially to harmonize with another wiki, I say go for it. My only two thoughts :
:* I think the monad concept itself is difficult enough that it warrants some motivation and exposition. In other words, maybe [[WP:NOTAGUIDE]] should be done with a chisel instead of a sledgehammer on this one. I know my edits were still too conversational in retrospect, but for example, it might still be helpful if sections are allowed to build on each other.
:* Referring to the Haskell wiki pages is definitely less than ideal, but the talk page already saw a lot of back-and-forth on moving away from Haskell more. I think the core issue is that while we can do examples in other languages, we don't have a better idiom than Haskell-ish terms and pseudocode for explaining the actual concepts. A lot of the historical record out there on using monads is based in Haskell too. Even if it's still Haskell-centric, another harder reference (like a book) might be a good first step. At least that gets us away from citing Haskell's community wiki.
:Like I said, I can't dedicate much time to this article going forward, but if you think I can help somehow, feel free to ping me. -- [[User:Zar2gar1|Zar2gar1]] ([[User talk:Zar2gar1|talk]]) 18:05, 21 November 2024 (UTC)
 
== Confusing Introduction ==
: I agree. I changed it to read "Since the bind operator is associative and non-commutative, this constrains the execution into a sequence." Because of associativity there is no hierarchy and because of lack of commutativity the operations must act in the given order. --[[User:TuukkaH|TuukkaH]] 06:21, 4 April 2006 (UTC)
The first paragraph refers to two ''operations'': "return : <A>(a : A) -> M(A)" and "bind : <A,B>(m_a : M(A), f : A -> M(B)) -> M(B)". The notation is not explained nor is there a link to a resource to understand them. There is a slight attempt to explain them with "which lifts a value into the monadic context" and "which chains monadic computations", but in introducing the idea of monads &mdash; which I'm still trying to understand &mdash; such things only serve to confuse. For example, what's a ''monadic context'' and why must a value be ''lifted'' into that context?
 
That same paragraph purports to provide a simpler explanation via, "In simpler terms, monads can be thought of as interfaces implemented on type constructors, that allow for functions to abstract over various type constructor variants that implement monad." However, I have no idea what a type constructor is, how functions can ''abstract over various type constructor variants'', or what it means for such type constructors to "implement monad", so how does any of that jargon help me figure out what a monad is?
==Rewrite on 2006-05-08==
[[Special:Contributions/141.162.102.57|141.162.102.57]] ([[User talk:141.162.102.57|talk]]) 16:56, 5 February 2025 (UTC)
I rewrote large sections of this article because I cited it for someone who wanted to know what monads are, he told me it didn't make any sense, and I agreed. Mainly, I made it less heavy on mathematical formulas. It's now heavy on Haskell, but I think that's appropriate because Haskell is the main promoter of monads, and this lets people download a Haskell system and try the code. [[User:Gazpacho|Gazpacho]] 03:59, 9 May 2006 (UTC)
 
: I don't think this was a good idea. Mathematics is universal across languages. Haskell is not. Perhaps a little bit of explanation of Haskell's syntax would be in order, or else just use pseudocode. Also, since you do say that there exist formulations in Scheme and Perl, perhaps a reference to those formulations would be nice. The section that existed previous to your edit which defined for instance the bind operator is much more clear than the current version. Please re-add a section describing the notation used, because unless you already know Haskell, it doesn't currently make a lick of sense.
 
The current version of the article is extremely Haskell-centric. There are plenty of tutorials on Haskell monads on the web. There's no need for the Wikipedia article to be one as well.
 
Just to be clear, I don't have a problem with the use of Haskell as the language to illustrate monad concepts. But the current presentation is very much "here's how to use monads in Haskell". In particular, phrases like "To define a monad in Haskell...", and the discussion of Haskell's do-notation seem more appropriate for a Haskell article than a general article on monads in FP. --[[User:Allan McInnes|Allan McInnes]] <small>([[User talk:Allan McInnes|talk]])</small> 20:22, 22 June 2006 (UTC)
 
Unfortunately, I agree that if it's too abstract people won't actually be able to learn from it. For people coming from a CS rather than a maths background, Monads are rather tricky.<small>—The preceding [[Wikipedia:Sign your posts on talk pages|unsigned]] comment was added by [[User:203.59.86.86|203.59.86.86]] ([[User talk:203.59.86.86|talk]] • [[Special:Contributions/203.59.86.86|contribs]]) {{{2|}}}.</small>
 
I agree too. I'm trying to completely grasp continuations as monads so I can add them to this. In the papers I've looked at thus far, most of them use Haskell. It'd probably be best to keep the explanation here as is, but move some of the Haskell-centric stuff (like the do-notation stuff) to another page --[[User:NotQuiteEXPComplete|NotQuiteEXPComplete]] 12:25, 3 August 2006 (UTC)
 
== Editorial wish-list ==
 
I wish there was a way to include comments right in the article on Wikipedia, but we don't have that, so I'll try to explain where I want changes. My comments refere to the version as of http://en.wikipedia.org/w/index.php?title=Monads_in_functional_programming&oldid=84889989
 
Section Motivation: the first code example: I think this is Haskell code, but it's not apparent that it really is. Please be explicit about that. "par" is a bad function name; it isn't obvious that it has anything to do with parallel connection of resistors. Better to call it foo, or something.
The syntax of the two lines of code is not obvious. The meanings of :: and -> are non-obvious.
 
Second code example:
Is ... a part of the code? The meaning of :: and -> are again non-obvious.
In an electrical engineering program, I'd like to use // as an operator means 1(1/x + 1/y), i.e., parallel connection, since the operator consists of two parallel lines. Therefore it's a bad choice for the meaning here; a new form of division.
 
The last sentence of the code example suggest that the example is wrong. Is it?
 
Section Definition: Shouldn't this be a definition of monads in functional programming, rather than monads in Haskell?
 
What does | (vertical bar) mean?
 
Are the words "data", "Just", "Nothing", parts of the Haskell language?
 
Is the character <code>&equiv;</code> a part of the Haskell language?
 
 
Section Failure:
Is the word "mzero" a part of the Haskell language, or of functional programming vocabulary?
 
 
The Maybe monad example: What does "'", "in" and "let" mean?
 
The rest of the article is left for a later time.
 
:You can include comments just fine. "<nowiki><!-- Comment on FOO --></nowiki>" does it just fine inline. --[[User talk:Gwern |Gwern]] [[Special:Contributions/Gwern | (contribs)]] 21:00 [[27 November]] [[2006]] (GMT)
 
== Rename? ==
 
Shouldn't [[Monad (functional programming)]] be the main name of this article? The discussion above doesn't really explain the reason for the name. --[[User:Bkkbrad|Bkkbrad]] 01:44, 26 December 2006 (UTC)
 
== Haskell code correct? ==
 
My haskell is a bit rusty, but it seems to me that<br />
'''(return x) >>= f ≡ f x'''<br />
should be<br />
'''(return x) >>= f ≡ return (f x)'''<br /> <small>—The preceding [[Wikipedia:Sign your posts on talk pages|unsigned]] comment was added by [[Special:Contributions/129.29.227.4|129.29.227.4]] ([[User talk:129.29.227.4|talk]]) 13:16, 27 March 2007 (UTC).</small><!-- HagermanBot Auto-Unsigned -->
 
:I don't think so...if '''x''' has type '''a''', and '''f''' has type '''a -> m b''', then '''return x >>= f''' will have type '''m b''', the same as '''f x'''. '''return (f x)''', on the other hand, will have type '''m (m b)''', since return has type '''a -> m a'''. [[User:Nick8325|Nick8325]] 14:52, 27 March 2007 (UTC)
 
== Readability/Understandability? ==
 
So I don't understand what Monads are, and after reading the article twice, I still don't know. The opening of the article explains what they are used for, but not what they are. The 'maybe' example is semi-understandable, but nothing explicitly states what problem Monads are solving. The definition given is nice and formal but totally inaccessible to anyone that doesn't already know what's being talked about. Is there some analogy that might be used to explain it? I haven't written a lot of code in functional languages (although I have written a little), never used Haskell, but I do have a Ph.D. in software engineering. [[User:68.4.228.48|68.4.228.48]] 17:38, 10 June 2007 (UTC)
 
: Wikipedia is [[WP:NOT#HOWTO|not a tutorial]]. The article links to the Haskell Wikibook's ''[[wikibooks:Haskell/Understanding monads|Understanding monads]]'' section; failing that, the Haskell wiki has a diverse list of other [http://haskell.org/haskellwiki/Monad#Monad_tutorials monad tutorials]. --[[User:Piet Delport|Piet Delport]] 04:55, 11 June 2007 (UTC)