links
links copied to clipboard
Support for first-class operation polymorphism
Currently, operation polymorphism is unsupported, nevertheless one can define an exception handler with the following type signature:
sig catch : (() {Fail:forall a.a |e}~> b) {Fail{_} |e}~> Maybe(b)
fun catch(m) {
handle(m) {
case Fail(k) -> Nothing
case Return(x) -> Just(x)
}
}
Note, the Fail
operation is supposedly polymorphic. The exception handler does not behave as intended:
links> fromJust(catch(fun() { 42 }));
fun : int
I suppose part of the issue is that in general Op:a
gets desugared into Op:() {}-> a
, thus Fail:forall a.a
becomes Fail: () {}-> (forall a. a)
which clearly is not what we intended.
I will look into adding proper support for operation polymorphism.
Some typing/inference strangeness I just stumbled upon
links> sig f : () {Foo:() -> forall a.a |e}~> forall b.b fun f() { do Foo() : forall a.a };
f = fun : () {Foo:() {}-> forall a.b|_}~> forall d.b