4 ms·
> I think the lesson is that tricky concepts have to be taught by example. The bigger insight, for me, is that they also have to be taught by counter-example.
by pdpi 2y ago
> I think the lesson is that tricky concepts have to be taught by example.
The bigger insight, for me, is that they also have to be taught by counter-example.
E.g. it's easy to find Functors that are neither Applicatives nor Monads (usually, because you can't produce a reasonable definition for `return`). It's surprisingly hard to find a non-contrived example of a Functor that is also an Applicative, but *is not* a Monad. Without that counter-example, it's very tricky to build the intuition for where the boundary lies.
- andrepd 2y agoNow I'm curious: what's this non-contrived example?
- pdpi 2y agoValidation. You can think of it as shaped like Either [Error] Value, but the implementation is different. Consider this example: pure . Config <$> validate option1 <*> validate option2 <*> validate option3 Either would short circuit on the first validation error. There’s two interesting things here though: there are no data dependencies between different validations (so we don’t _need_ a monad), and it’s useful to accumulate errors to know if both option1 and option3 failed to validate (so we don’t _want_ the Either monad’s short circuiting behaviour). The implementation is pretty straightforward, too!