3 ms·
> 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 mona
by 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).