5 ms·
It's also wrong. Lists are monads, and whether the implementation you use is mutable or not is not relevant to how you use them. The essence of monads is not a
by pyrale 4y ago
It's also wrong. Lists are monads, and whether the implementation you use is mutable or not is not relevant to how you use them.
The essence of monads is not about what use can be made of them either, just like the essence of things that have a hook is not that you can use them to hang your coat.
Simply put, monads are data types that share a set of properties. Think of them as you would think of the atoms that are halogens, or of the animals that are mammal. In the case of monads, the property is that functions can be chained on them in a specific way, and that the result of this chaining respects some rules.
The reason it is so hard to explain or understand monads is that this property in many different ways for many different ends, and that the what and the why are often mixed in the explanation.
- deleted 4y ago[deleted]
- quelltext 4y ago> Lists are monads Isn't it just that you can define monadic interfaces for lists, as you can with (probably all) parametric data types? Saying "the list monad" wouldn't be correct, right? Although it's pretty common to see that phrase.
- jerf 4y agoMonad is just an interface; all "monad"s are things that declare some function that conforms to the interface. You can say "the list monad" reasonably because there is only one sensible implementation of (List a -> (a -> List b) -> List b) in Haskell. You could unconditionally return an empty List b and fulfill that interface, but what would be the point of that? You can't just return a list of all the things the function call resulted in because that would be a List of a List of b, which is not the same as a List of b. You can't sort them in Haskell because you don't have any form of comparability available in that interface specification. etc. Technically in other languages this may be less true as due to having fewer restrictions (for example, you may in a language that defines ordering on all values, and thus you could sort the result regardless of the types involved) you can do more things, but there's still really only one sensible and unsurprising implementation.
- simiones 4y ago> You can say "the list monad" reasonably because there is only one sensible implementation of (List a -> (a -> List b) -> List b) in Haskell. While this may be true, I think the main reason you hear "the list monad" in Haskell is that Haskell doesn't support multiple instances of a type class (such as Monad) for a single data type (such as List/[]); and the Prelude already includes such an instance, which then becomes the List Monad. This limitation is perhaps not often relevant for Monads, but it is sometimes relevant for other Algebraic structures. For example, there are two very common Monoids on Number: (Number, +, 0) and (Number, *, 1).
- pyrale 4y ago> You can't sort them in Haskell because you don't have any form of comparability available in that interface specification. etc. Technically, if you were the pervert kind of developer, you could revert the list.
- pyrale 4y agoYou can define monadic interfaces for lists because lists are monads. It would therefore be correct (but slightly pedantic) to talk about "the list monad". > as you can with (probably all) parametric data types? Actually, you can't. For instance, if you define a predicate type: `data Predicate a = Predicate (a -> Bool)` It is not a monad, it's not even a functor. (If you're interested in what it is you can look into contravariant functors).
- sudosysgen 4y agoLists are absolutely not monads. There are implementations of interfaces on lists using monads, but a monad is a specifically designed term, that requires a lifting function and monadic combinators which are simply not part of the definition of the list. The understanding of the monad as a wrapper with a combinator equivalent to function composition is simply correct.
- nightski 4y agoI don't like being adversarial but this is wrong. https://www.schoolofhaskell.com/school/starting-with-haskell/basics-of-haskell/13-the-list-monad https://www.schoolofhaskell.com/school/starting-with-haskell... A list is absolutely a monad.
- sudosysgen 4y agoThe Haskell list is implemented as a monad. A list in general isn't a monad. You can use Monads to implement lists, but that doesn't make them Monads anymore than saying that lists are generic container classes.
- nightski 4y agoDo you have an example of a list, which meets the mathematical definition, which would not be able satisfy the requirements of a monad? Meaning one could not write a bind or lift operation for that list?
- sudosysgen 4y agoNo, you deeply misunderstand what a monad is. Monad doesn't mean you can write the bind and lift operations, a monad contains the bind and lift operation. The bind and lift operation is a component of the monad. You could probably shoehorn some kind of bind and lift into any conceivable generic type.
- pyrale 4y ago