Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[proposal] new interface in deeplang #28

Open
3 tasks
chinesebear opened this issue Sep 26, 2020 · 2 comments
Open
3 tasks

[proposal] new interface in deeplang #28

chinesebear opened this issue Sep 26, 2020 · 2 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@chinesebear
Copy link
Contributor

  • discuss interface solution
  • update deeplang SPEC
  • plan of interface implementation

非侵入式接口

interface I {
    fun f()
    // var f: ()->unit
}

class Foo {
    fun f() {
        println("")
    }
}

class Bar implements I {
    fun f()
}

fun useI(i: I) {
    i.f()
}

useI( new Foo() )

struct String {
    fun f() {}
}

enum Color {
    fun f() {}
}

扩展

extension

在原来类型的基础上,添加新的函数。

class Foo {
}

extension Foo {
    fun run() {
        this.xxxx
    }
}
/*
fun Foo_run(this: Foo) {

}
*/

extension Foo {
    fun f() {}
}

fun main() {
    let x = new Foo()
    x.run()
    useI( new Foo() )
}

extension Foo implements I {
    fun f() {}
}

extension String {
    fun reverse() -> String {
        .....
    }
}

"123".reverse()

委托

将一个子字段field的成员(field,method)都委托到当前层级。

class A {
    let x: Int
    fun hello() {
        ......
    }
    fun f() {}
}

// class B : A {}

class B {
    as let a: A
}

let b = new B()
b.x // b.a.x
b.hello() // b.a.hello()
b.f()

useI( b )

// 如果委托的字段,有重现同名的成员(field,method),这个同名的成员就不会被委托。
class C {
    fun f() {}
}

class B {
    as let a: A
    as let c: C
    fun f() {
        c.f()
    }
}

struct D {
    fun f() {}
}

struct E {
    as let d: D
}
type A struct {
    v int
}

type B struct {
    A
}
@JoeyTeng
Copy link

赞成引入这个类型系统设计,不过需要描述文档而不仅仅是不完整的示例

@kulics
Copy link

kulics commented Oct 6, 2020

稍晚我写成详细的描述文档,再补充些细节

@chinesebear chinesebear changed the title new interface in deeplang [proposal] new interface in deeplang Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants