effekt-lang / effekt

A language with lexical effect handlers and lightweight effect polymorphism
https://effekt-lang.org
MIT License
334 stars 24 forks source link

Super-issue: Rethink / re-design "object-system" #605

Open marzipankaiser opened 2 months ago

marzipankaiser commented 2 months ago

In general, we need to rethink / redesign the "object-system" anyways. Some aspects are:

See also

marzipankaiser commented 2 months ago

(Of course, feel free to add/edit/make sub-issues etc)

b-studios commented 2 months ago

I'd like to be able to allocate an object into a region (if it has mutable state).

new Foo(x, y) in {r}

or maybe

interface Foo {
  def op(): Unit
}

class Bar {r: Region} implement Foo {
  var field in r = 4

  def op() = { 
    r = r + 1; 
    this.helper() // it should be possible to invoke methods on the same object
  }

  // NOT part of the interface
  def helper() = println(r)
}

new Bar {global}
jiribenes commented 4 weeks ago

I'd like to be able to allocate an object into a region (if it has mutable state).

Would it also make sense to allocate a capability into a region? 🤔 (so that the return type is Counter at {r})

def makeCounter {r: Region} = {
  var count in r = 0
  try {
    println(c.get())
    c.increment()
    c.increment()
    println(c.get())

    c
  } with c: Counter in r {
//                  ~~~^
    def get() = resume(count)
    def increment() = { count = count + 1; resume(()) }
  }
}