by oleganza · 3y ago · 0 comments
Maybe because first-class support for lambdas was added too late in C++ and Java, or maybe because it was always PITA to type.
Ruby syntax is the lightest there could be (and it supports both {braces} and do/end keywords)
transaction do
foo()
bar()
endKotlin can have exactly the same code with lambdas, using either a receiver type, or a context receiver. And it's type safe.
transaction {
foo()
bar()
}
Type-safe DSLs become a pleasure to build and use. someTransaction = do
incrementCounter
writeFile "foo.txt" "bar"
decrementCounter
I get this: src/Lib.hs:11:5: error:
• Couldn't match type ‘IO’ with ‘STM’
Expected: STM ()
Actual: IO ()
• In a stmt of a 'do' block: writeFile "foo.txt" "bar"
In the expression:
do incrementCounter
writeFile "foo.txt" "bar"
decrementCounter
In an equation for ‘someTransaction’:
someTransaction
= do incrementCounter
writeFile "foo.txt" "bar"
decrementCounter
|
11 | writeFile "foo.txt" "bar"
| ^^^^^^^^^^^^^^^^^^^^^^^^^