41 ms·
I'm writing a bunch of webapps in Scala making heavy use of Scalaz, which is Scala's Haskell-envy library of typeclasses. The typical pattern is to compute ever
by noelwelsh 15y ago
I'm writing a bunch of webapps in Scala making heavy use of Scalaz, which is Scala's Haskell-envy library of typeclasses. The typical pattern is to compute everything as a Validation, which you can think of as the Maybe monad, except there is information attached to the failure case. It's a very nice way of coding. Everything composes and at the end of the request handling chain you just convert to a response and you're done.
It took a bit of thinking to get the basic patterns, and there is the occasional bit of head scratching to get the type right. This feels very much like algebra.
Anyway, the point is that this style of programming is both "mathematical" and practical.
- tikhonj 15y agoFor reference, Haskell's version of that is called Either. You also sometimes use ErrorT which is a way to slap an Either on any other Monad. The T just denotes that it's a monad transformer. Coincidentally, I agree wholeheartedly about how practical programming like this is--this sort of error handling is at once easier and more explicit than exceptions.
- jules 15y agoWhy is it easier? That's just doing the monad transformation by hand instead of letting a compiler take care of that for you (in the case of EitherT and do-notation the compiler takes care of the intraprocedural transformation for you). It's rather in the same category as Node.js programmers doing CPS transform by hand.