News for hackers. Stuff that matters.
Re:Monads are monoids in the category of endofunctors by deepsun on Friday September 10, 2021 @10:04AM (#28481733)
So we cannot talk about a type being monad without also saying under what function?

E.g. Arrays are monads under concatenation. So why people then say easily "Option type is monad" without stating under which operation? I assume Option is monad under "all" and "any" function, but not sure.

Re:Monads are monoids in the category of endofunctors by lkitching on Friday September 10, 2021 @11:10AM (#28482655)
A monad is a triple:

1. A type constructor M of a single argument 2. A function of type a -> M a 3. A function of type M (M a) -> M a

subject to the monad laws. So the 'array monad' is the triple (Array, \x -> [x], Array.concat) and the 'option monad' is the triple (Option, \x -> Some(x), \x -> match x | Some(o) => o; None => None). Saying a type 'is' a monad is imprecise but just means it has an associated monad instance. I've never seen a type with multiple monad instances but I don't know if there could be one.

Re:Monads are monoids in the category of endofunctors by edflsafoiewq on Friday September 10, 2021 @03:52PM (#28486199)
> I've never seen a type with multiple monad instances but I don't know if there could be one.

There can, it's just like there can two monoid structures on the same set. In fact if you have an example of a set S which has two monoid structures, you have an example of a functor with two monad structures: _ × S. join multiplies the two elements of S, so you get a different monad structure for every monoid structure on S.

Re:Monads are monoids in the category of endofunctors by deepsun on Friday September 10, 2021 @02:48PM (#28485602)
Wow that's clearer. I wonder if just a list of examples (and counter-examples) would be enough to explain monads (preferrably with configurable syntax for Haskell-deprived folks).

Btw, I think you got a mistake there, in the third part of Option should be "Some(Some(o)) => Some(o), Some(None) => None, None => None", otherwise o can be not an Option at all.

Re:Monads are monoids in the category of endofunctors by lkitching on Monday September 13, 2021 @10:42AM (#28512115)
Your first two cases are equivalent to the `Some(o) => o` case; the syntax I used was a bit ad-hoc but the following F# typechecks:

    let join_option oo =
        match oo with
        | Some(o) -> o
        | None -> None
Re:Monads are monoids in the category of endofunctors by edflsafoiewq on Friday September 10, 2021 @10:17AM (#28481892)
Yes, but its usually obvious which one is meant, so you don't bother saying under what operation. Option is a monad under the same concatenation as Array, just think of them as arrays that always have length 0 or 1.
Re:Monads are monoids in the category of endofunctors by deepsun on Friday September 10, 2021 @02:50PM (#28485620)
How to concatenate Option-s? Btw your comment seems to contradict another sibling comment.
Re:Monads are monoids in the category of endofunctors by edflsafoiewq on Friday September 10, 2021 @03:43PM (#28486111)
Like I said, view them as an array with 0 or 1 element and do it just like for arrays. There are only three possibilities:

  [] => []
  [[]] => []
  [[a]] => [a]