Skip to content

CJPLUK/effects-alt-syntax

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Effect Handlers (non-deferred) Without Special Syntax

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.

Setup

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" }

Minimal Example

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
}

About

Effect handlers without the special syntax

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published