I am currently learning Applicatives in Haskell. If I am not wrong, there are two different Applicative instances for Lists, (List
and ZipList
- the second being defined as a newtype wrapping a List value). The ZipList
applicative instances seems more intuitive for me.
It might be a dumb question, but is there a specific reason ZipList
is not the default Applicative instance for Lists.
pure (+) <*> [1,2,3] <*> [4,5,6]
-- [5,6,7,6,7,8,7,8,9]
pure (+) <*> ZipList [1,2,3] <*> ZipList [4,5,6]
-- ZipList [5,7,9]
Is it because the distributive version of Applicative List also happens to have a Monad instance?
I suspect the honest answer here is "historical accident". The monad abstraction was popular before the applicative one was; since there is a natural list monad, that instance was defined. For backwards compatibility, it makes sense to keep the functor and applicative instances consistent moving forward.
That said, if we had to make the choice again today, I think I would support the current situation anyway: the nondeterminism monad is useful as a syntactically cheap backtracking search, and I've taken advantage of that frequently; arbitrary-arity zipping is (in my personal experience) a much less frequent need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With