[HN Gopher] What does it mean for a monad to be strong?
       ___________________________________________________________________
        
       What does it mean for a monad to be strong?
        
       Author : chmaynard
       Score  : 32 points
       Date   : 2023-08-21 18:49 UTC (4 hours ago)
        
 (HTM) web link (blog.sigfpe.com)
 (TXT) w3m dump (blog.sigfpe.com)
        
       | koolala wrote:
       | In my own personal monad opinion, the 'strongest' idea of a monad
       | to me is just a function or program.
       | 
       | monad 1 | monad 2 | monad 3
       | 
       | It doesn't have to be complicated.
        
         | Sharlin wrote:
         | The whole point of the article is that the right-associativity
         | of Haskell monads makes them not simple pipelines because it
         | allows this:                   a -> b -> c          \_______^
         | 
         | so c gets the results of both a and b "for free".
        
           | koolala wrote:
           | So how do you generalize this idea to programs and functions?
           | My framing is "incorrect" I think but it feels far easier to
           | reason about.
           | 
           | Couldn't this same idea be applied generically to all
           | computer programs? Could its valuable situational properties
           | ever be done in a way that is language neutral with arbitrary
           | program monads?
        
             | kfixjviv wrote:
             | The main reason that monads are restricted to fancy
             | languages like Haskell is that the type system has to
             | support their definition.
             | 
             | There are some examples of attempted implementations the
             | list monad in other languages on RosettaCode
             | https://rosettacode.org/wiki/Monads/List_monad
             | 
             | Caveat emptor, though. A lot of that page is erroneous.
             | 
             | A few years ago I fixed up the definition for F#, which is
             | perhaps the closest thing to a language for ordinary Joes
             | in which true monadic style can be defined/achieved.
        
         | MaxRegret wrote:
         | I think the article is an attempt to make your idea more
         | precise. What if monad 3 could use the result of monad 1, not
         | just monad 2? Then you couldn't write that computation using
         | your pipeline metaphor.
         | 
         | The article is saying that by judicious use of a "strength"
         | function, you can in fact write any monadic computation as such
         | a pipeline (or composition of monadic functions).
        
           | koolala wrote:
           | If my example of pipeline is a limited metaphor, couldn't it
           | be expanded?
           | 
           | I love this subject but it's traditionally over-complex, so I
           | appreciate the correction and explaination.
           | 
           | How could "strength" be applied generically to programs
           | outside of Haskell? Could the concept of pipelines be
           | extended? Is programming too 1 dimensional? There must be
           | ways to do this.
        
       | hgsgm wrote:
       | So, strength is the ability to write a monad-related function you
       | can define if you need to, like any other function you might
       | write that had a monad argument. But you can't not in math
       | monads, for reasons not explained.
       | 
       | I don't see how this helps anyone.
       | 
       | What is different about a math monad that makes strength no
       | available, and why is that interesting?
       | 
       | How would you create a non-strong monad in Haskell, and why might
       | you want to, or is it impossible?
       | 
       | Seems to lean to much on a sort of false connection between
       | Haskell and math, where two similar but different things have the
       | same name.
        
         | bPspGiJT8Y wrote:
         | > How would you create a non-strong monad in Haskell, and why
         | might you want to, or is it impossible?
         | 
         | I think the article implies it clear enough that it's
         | impossible. Even if your monad has nonsensical (but lawful)
         | semantics like `Proxy t` it's still possible to use it with
         | `strength`. BTW the `strength` function is called `sequence`.
        
           | kfixjviv wrote:
           | Haskell's sequence is not the same as strength. Strength
           | specifically involves pairs.
           | 
           | Nobody seems to know where "strength" got its opaque name
           | from. Like, nobody, not even the guy who first published the
           | term.
           | 
           | There is another article on the topic here:
           | 
           | http://comonad.com/reader/2008/deriving-strength-from-
           | lazine...
        
         | MaxRegret wrote:
         | I agree that it would be interesting to learn what non-strong
         | monads look like. But the blog post does (implicitly) answer
         | some of your questions:
         | 
         | It says that all monads in the Set category are strong. That
         | would include Haskell monads, at least those expressed in the
         | usual way as type constructors, to the extent that Haskell
         | types model sets.
         | 
         | And you can see that the "strength" operation relies on the
         | existence of tuples behaving like Cartesian products of sets.
         | Such objects might not exist in other categories.
        
         | mkoubaa wrote:
         | "I don't see how this helps anyone" is my gut response to
         | anything related to the m-word
        
           | mgaunard wrote:
           | Monads are just a way to bind a continuation to an
           | expression.
           | 
           | The only reason they sound special is the silly name and the
           | inane Haskell syntax.
        
             | throwaway17_17 wrote:
             | I find this to be an odd take. Monads, even when restricted
             | to programming language usage, do not fundamentally have
             | anything to do with continuations. There is a Continuation
             | Monad in Haskell, but that is just one implementation of
             | one example of a monad.
             | 
             | I'm not particularly sold on the Ur-importance of monads in
             | programming, but I don't get using such a specific
             | implementation to deride the concept. Monads are an
             | algebraic structure, application in programming languages
             | is akin to using sum types to form enumerated data.
        
         | tikhonj wrote:
         | As a wild guess, this same construct might not always work with
         | linear types--if we had to use x exactly once, we wouldn't
         | always be able to write `return (x, y)`. I haven't really used
         | them, but linear types _are_ supported in Haskell, and you can
         | generalize the Monad class to be able to handle them. This
         | would conceptually correspond to x being some sort of limited
         | resource that we can 't copy arbitrarily, which is more than a
         | purely mathematical curio.
         | 
         | In mathematics more broadly, the fact that you don't _always_
         | have the equivalent of the `strength` function is useful
         | because it lets us work with different kinds of products than
         | just tuples. This can even be useful for practical work: we
         | might want to model something like hardware or quantum
         | computations which behave differently than  "normal" programs.
         | Requiring all monads in that context to support `strength`
         | would really restrict the sort of things you could useful model
         | _as_ monads.
        
         | hackandthink wrote:
         | >What is different about a math monad that makes strength no
         | available, and why is that interesting?
         | 
         | Let's turn it around. Why is strength for Haskell Monads
         | interesting?
         | 
         | Answer: it enables a nicer do notation, you can use
         | intermediate values:
         | 
         | https://mroman42.github.io/notes/Pieces/Do-notation-for-stro...
        
       ___________________________________________________________________
       (page generated 2023-08-21 23:00 UTC)