links icon indicating copy to clipboard operation
links copied to clipboard

Support for first-class operation polymorphism

Open dhil opened this issue 7 years ago • 1 comments

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.

dhil avatar Feb 20 '17 14:02 dhil

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

dhil avatar Jun 13 '19 08:06 dhil