Re:What Color Is Your Monad
by shirogane86x on Thursday February 17, 2022 @06:05AM
(#30371818)
small 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 levelScala 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
I know the Haskell operators, but the Idris syntax are new to me.
BTW * has to be escaped with a \.
Re:What Color Is Your Monad
by shirogane86x on Thursday February 17, 2022 @02:39PM
(#30377656)
I 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
---
> 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.