This package provides a way to use effect handlers in Cangjie
without the need for the special try-handle syntax hidden behind
the experimental flag --enable-eh.
Warning
This does not allow for deferred resumptions, see the deferred-resumption branch for that.
Add this package as a dependency to your cjpm.toml config file with the following:
[dependencies]
effects = { git = "https://github.com/Huawei-Edinburgh-Programming-Languages/effects-alt-syntax.git", branch = "immediate-handlers" }import effects.*
class Effect <: Command<Int64> {
Effect(let x: Int64) {}
public func defaultImpl() { x }
}
main(): Int64 {
println("Default implementation:")
println(perform(Effect(6)))
let message: String = try_with_effects({=>
println("With different handler:")
println(perform(Effect(6)))
return "aoeu" // a value returned in this block is returned by the whole try_with_effects call
}, Handle { e: Effect => e.x + 1 }
// Optional "finally clause":
// , Finally {=> println("...finally")}
)
return 0
}