Eliminating "seemingly unnecessary" braces

In Haskell you would use a higher order function for a loop and there is the "lambda case" syntax extension that allows for using pattern matching and multiple branches directly in an anonymous function. This looks like

for_ myCollection \case
  Just x -> {- do something with x -}
  Nothing -> {- do something on Nothing -}

Where Just and Nothing are the Haskell equivalent of Some and None and Iʼm also using another syntax extension "block arguments" to avoid having to write a $ before the \.

Edit: to clarify, Haskell does not even have any special syntax for for-loops in the first place, and “translating” the lambda-case syntax to Rust would roughly look like

my_collection.for_each(|match| {
    Some(x) => /* do something with x */,
    None => /* do something on None */,
})

where

|match| { /* ... */ }

would be new syntax sugar translating to

|_x| match _x { /* ... */ }

similar to how in Haskell with the LambdaCase feature

\case {- ... -}

translates to

\_x -> case _x of {- ... -}
2 Likes