goodlang / good

The Good Programming Language
BSD 3-Clause "New" or "Revised" License
29 stars 3 forks source link

Multisignatures #12

Open kirillDanshin opened 7 years ago

kirillDanshin commented 7 years ago

Let's say we have this struct:

type SomeStore struct {
    b int
    c string
    d float64
}

User should be able to define functions like:

func Store(n int) *SomeStore {
    return &SomeStore{b: n}
}
func Store(c string) *SomeStore {
    return &SomeStore{c: c}
}
func Store(d float64) *SomeStore {
    return &SomeStore{d: d}
}

And methods:

func (s *SomeStore) Set(n int) {
    s.b = n
}
func (s *SomeStore) Set(c string) {
    s.c = c
}
func (s *SomeStore) Set(d float64) {
    s.d = d
}

And more on methods:

func (a *A) Set(anotherA *A) {
    a.b = anotherA.b
    a.c = anotherA.c
    a.d = anotherA.d
}
func (a *A) Set(c string) {
    a.Set(15<<2, c)
}
func (a *A) Set(c int, d string) {
    a.b = c
    a.c = d
}
onokonem commented 7 years ago

I've used this in my Java days.

finally I found it is more convenience to have clear methods name

alexclear commented 7 years ago

Multidispatch for the win!