
On Thu, Feb 19, 2015 at 4:42 PM, Christopher Done
On 19 February 2015 at 16:29, Erik Hesselink
wrote: If I'm reading it correctly, the only example where a fold wouldn't work is <*>, right? And probably conduits, I don't know the types there.
Right, I see three use-cases:
* Some things are foldable cleanly like monoids, so you can just mconcat [x,y,z] and that'll be inlined (I think). * Other things like x <|> y is not the same as asum [x,y] due to the additional mempty being introduced. You can also use foldl1 kind of functions, but they are partial and therefore not desirable.
Do you mean execution-wise? Because semantically there should be no difference, I think. Although now that I think of it, there might be for things that carry information in the mempty case, like ErrorT, when they are right biased. It could be argued that this is a bug, and ExceptT fixes it. You could write monoids that do the same thing, e.g. instance Monoid b => Monoid (Either String b) where mempty = Left "" mappend (Right x) _ = Right x mappend _ y = y I have a feeling that `Alternative (f a)` should satisfy the Monoid laws for `Monoid (f a)`, but that doesn't seem to be documented. It does say 'a monoid on applicative functors', so perhaps it's implied.
* Finally, things like <*>, $=, $, ., #/:& (e.g. in HList/vinyl) can't be folded at all, because the types are different.
The third use-case doesn't have a solution that I'm aware of. So this solves that. It also solves the second use-case, which has only a partial (he he) solution. The first use-case is just a bonus. Should I add this clarification to the proposal?
Yes, that sounds good. It wasn't immediately obvious to me in the first paragraph why you would want this, and after the examples, I thought "meh". This list is very clarifying, and the third bullet is much more convincing to me. Erik