links-lang / links

Links: Linking Theory to Practice for the Web
http://www.links-lang.org
Other
333 stars 43 forks source link

Polymorphic operations #1163

Closed dhil closed 1 year ago

dhil commented 1 year ago

Clean-up of #1158.

This patch adds support for polymorphic operations.

For this we have to annotate the cases in the handler with polymorphic operation types.

Example

sig h : (Comp(b, {A:forall a. (a) => a, Fail:forall a. a|c})) {A{_}, Fail{_}|c}~> Maybe(b)
fun h (m) {
    handle(m()) {
        case <A(x) => k> : (forall a.  (a) => a) -> k (x)
        case <Fail> : (forall a. () => a) -> Nothing
        case x -> Just(x)
    }
 }

sig f : () {A:forall a. (a) => a|_}-> Int
fun f () {
    if (do A(true)) do A(1) else
    do A(42)
}

This is done by having actual operation patterns and using the type annotation system associated with it.