-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Description
It seems to me that Selective functors could in principle desugar more do notations than Applicatives. For example:
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"I believe this has the same semantics as:
main = maybe (Right (Left ())) Left . (readMaybe :: String -> Maybe Int) <$> getLine
<*? (putStrLn "Yes, that's a number" *> pure (const (Right ())))
<*? (putStrLn "Nope, not a number" *> (pure id))The latter only needs Selective.
In general, all if statements could be desugared into Selective, and case could be desugared iff the variables bound in the branches are not used in a binding way.
I've asked some of this here: https://discourse.haskell.org/t/efficient-selectivedo-and-binary-search/1657/3 but I wanted to know your opinion. I think this would be interesting, especially in situations where no efficient monads exist, e.g. some streaming approaches.
Metadata
Metadata
Assignees
Labels
No labels