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

Implement Polymorphism #9

Open
LemonHX opened this issue Oct 10, 2021 · 1 comment
Open

Implement Polymorphism #9

LemonHX opened this issue Oct 10, 2021 · 1 comment
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@LemonHX
Copy link
Collaborator

LemonHX commented Oct 10, 2021

draft:

a:int = 10
a:string = "string"

it will not throw type fail exception, instead a will be two instance one is typed int the other will be typed string

f = (a:int) -> int a
f = (a:string) -> string a

f now also has two instance

b:int = f(a) # will use the instance int -> int
b:string = f(a) # will use the instance string -> string
b = f(a)

but what if the type of b is not specified?
for simplicity just use the first type it matches.

@LemonHX LemonHX added the enhancement New feature or request label Oct 10, 2021
@LemonHX LemonHX self-assigned this Oct 10, 2021
@LemonHX LemonHX added this to the 1.0.0 milestone Oct 10, 2021
@LemonHX
Copy link
Collaborator Author

LemonHX commented Oct 15, 2021

better design
add keyword dyn

dyn a = 1 # dyn [number]
dyn a = "string" # dyn [string]
c = (x:number) -> number x
c(a) # number

rewrite

a = {}
a["number"] = 1
a["string"] = "string"
c = (x) x
c(a["number"])

just a syntax sugar for map

dyn f = (x:number) -> number {
    if x.lt(3)
        x.add(1).f
    else
        x
}
f = {}
f["number->number"] = (f)(x) if x.lt(3) x.add(1).f else x
f["number->number"] = f["number->number"](f["number->number"])

rewrite
ignore dyn rewrite let rec

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

1 participant