Skip to content

Do you want a SelectiveDo proposal? #40

Description

@turion

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions