3 ms·
Well it means that if you've got a parser that returns 'a' and a function from 'a' to 'b' then you can make a parser that returns 'b'. And if you've also got a
by contravariant 3y ago
Well it means that if you've got a parser that returns 'a' and a function from 'a' to 'b' then you can make a parser that returns 'b'. And if you've also got a function from 'b' to 'c' then function composition basically does what you'd expect.
Which, you know, sounds extremely trivial.
The applicative part is a bit more interesting, it means if you've got a parser that returns a function 'a -> b' and a parser that returns an input 'a' for that function then you can make a parser that returns 'b'. This would have been interesting in general categories, but in Haskell function types with currying and application isn't really a remarkable feature so preserving this structure becomes more of a necessity than an interesting feature.
- marcosdumay 3y agoWell, I've had to use parsers in other languages that weren't pure or where one couldn't just translate the "Result a" equivalent to "Result b". That always lead to a bunch of annoyingly error-prone boilerplate. But yeah, that's it. I'd say that half of the Haskell's value is avoiding a bunch of annoyingly error-prone boilerplate... everywhere and recursively.
- contravariant 3y agoYeah I suppose that is the other side of the coin. Knowing about functors makes it easier to intuit what utilitu functions to write to avoid boilerplate. But sometimes the 'mysticism' gets in the way, this article spends a lot of words on technicalities but very little on the intuition that this should be fairly trivially true. This might make sense in the context for which this article is written, but why this article is on the front page of HN I don't understand.