I’m surprised there is no more talk about a SelectiveDo proposal. It should be possible to use selective to desugar e.g. the following:
main = do
n <- readLn
if n > 23
then putStrLn "Too large"
else putStrLn "Fine"
The desugared code should be equivalent to main = ifS ((> 23) <$> readLn) (putStrLn "Too large") (putStrLn "Fine"). Crucially, it doesn’t need a Monad instance, only Selective! It would be great to be able to use syntax like that e.g. in parser combinators or libraries with parallelizable effects. Case analysis should work as well.
There was a brief discussion about this on Reddit, and the upshot was:
- It’s not just a straightforward
RebindableSyntax, becauseSelectivedoesn’t have a straightforward bind operator. So directly desugaringifandcasewould bring something novel. - There is a very inefficient
bindSoperator that only works onBoundedtypes and basically makes a branch for every single value. This is of course horrible for larger types:
> return (10000 :: Int) `bindS` print
*** Exception: stack overflow
To work around this issue, I’m working on a type class Bisect a which has a method bisect :: a -> a -> a to make the branching logarithmic in the size of the type, using binary search. But that type class then has to be derived or written for every single datatype, which is still not as nice as a new desugaring.
So, long story short: Why is there not more buzz around a SelectiveDo proposal?