Yes, exactly. Basically when a is finite in the sense that it can be enumerated or bisected, then you can bindS it.
I’d also have said that you can recurse! Obviously, you can just recurse in Haskell, but then static analysis of the program defined with recursion might hang, taking potentially infinite time to analyse it because the program itself may be infinite.
Maybe it would be interesting to have something analogous to MonadFix instead?
class Selective f => SelectiveFix f where
sfix :: (a -> f (Either a b)) -> f b
But that type signature just speculation. No idea whether there are sensible implementations that allow us to write programs we want. Maybe there is a better type signature for sfix.
Again, I agree. Programs like this should be desugarable into Selective:
main = do
number <- (readMaybe :: String -> Maybe Int) <$> getLine
case number of
Just _dontuseme -> putStrLn "Yes, that's a number"
Nothing -> putStrLn "Nope, not a number"
As long as we branch into ifs and cases, and don’t use bound variables in cases, it should work.
See Do you want a SelectiveDo proposal? · Issue #40 · snowleopard/selective · GitHub and Efficient SelectiveDo and binary search - #3 by turion for discussion.