4 ms·
The examples for for-comprehension looks very compelling. But it's painful in practice. It is still way too clunky compared to line-by-line imperative* code.
by ackfoobar 5y ago
The examples for for-comprehension looks very compelling. But it's painful in practice. It is still way too clunky compared to line-by-line imperative* code.
something(a = effectfulA(), b = effectfulB())
This would be three lines in a for-comprehension. With noisy variable names.
---
> We can even combine things, so F could be CorrelationId => Promise<*>
And then you need to litter your code with `liftF` and whatnot.
---
*You are still doing imperative programming whether you use the language's built-in flow control or use an IO monad.
- shirogane86x 5y agosmall nitpick/counter example: in Haskell, you could make your example look like: something <$> effectfulA <*> effectfulB <$> and <> are very common in haskell code and basically second nature to any haskeller, and that's how I would personally write it (don't know if scala has equivalents). Idris in my opinion does this even better, in Idris it would look like the following: something !effectfulA !effectfulB -- using !-notation, or: [| something effectfulA effectfulB |] -- using idiom brackets the two exist separately because !-notation is more general, while idiom brackets abstract _only function application_, and they desugar to map (aka <$>) and ap (aka <>), rather than !-notation which desugars to bind (aka >>=, aka <- in do blocks) I think given these they are roughly equivalent, with the added benefit (at least IMHO) that the side-effectful/monadic actions are very clearly marked even at a syntactic level
- ackfoobar 5y agoScala has overloading, currying not-by-default, optional and named parameters. Some similar stuff exist*, but they interfere with those Scala features, which I value more. * https://eed3si9n.com/learning-scalaz/Applicative.html https://eed3si9n.com/learning-scalaz/Applicative.html I know the Haskell operators, but the Idris syntax are new to me. BTW * has to be escaped with a \.
- shirogane86x 5y agoI see that scala(z)'s operators are adapted from haskell which seems to make it quite nice, although I don't know the finer details. Also thanks for letting me know about the escaping, sadly I can't edit the comment anymore