Open PaperPrototype opened 1 year ago
Can you explain the idea again? I got lost between the two examples 😵 A full code example will be best I think.
As a side note I'd say....I'm not sure i'm ready to go into inheritance. Go diverted from it on purpose, as much as i miss it at points, dealing with all the edge cases that arise from inheritance might be a bit too big to handle at this point. WDYT?
Can you explain the idea again? I got lost between the two examples 😵
type Person {
public string Name
}
type Zombie extends Person {
public int32 InfectionAmount
}
interface IName {
public func GetName()
}
if @typeof(Person) == @typeof(Zombie) {
mut zombie = Zombie{
Name: "Abdiel"
infectionAmount: 12
}
mut person = Person(Zombie)
}
This is also using the new const
and mut
syntax from issue #3
As a side note I'd say....I'm not sure i'm ready to go into inheritance. Go diverted from it on purpose, as much as i miss it at points, dealing with all the edge cases that arise from inheritance might be a bit too big to handle at this point. WDYT?
By "inheritance" I mean literally the 0s and 1s layout of the structs would let us do a hard cast from one type to the other (as seen in above example code).
To put it visually
zombie
[Name, infectionAmount]
person = zombie
[Name] ~~~infectionAmount~~~
Although this would only be possible if goat ensured no field reordering could happen as mentioned in the C ABI issue #12
Just so I understand, if goat is to automatically translate goat
files to go
files - can you provide an example go
file produced from the following goat
file:
type Person {
public string Name
}
type Zombie extends Person {
public int32 InfectionAmount
}
interface IName {
public func GetName()
}
if @typeof(Person) == @typeof(Zombie) {
mut zombie = Zombie{
Name: "Abdiel"
infectionAmount: 12
}
mut person = Person(Zombie)
}
This reply is long overdo
package main
import (
"fmt"
"reflect"
)
type Person {
public string Name
}
type Zombie {
public Person Person
public int32 InfectionAmount
}
interface IName {
public func GetName()
}
// I this would be possible, but for now I'd say it reduces to compile time
/* if @typeof(Person) == @typeof(Zombie) */
var zombie = Zombie{
Person: Person {
Name: "Abdiel"
}
infectionAmount: 12
}
var person = zombie.person
Image the following code:
With C you can implement a very simple form of plymorphism by embedding a struct
Position
atop say another struct calledTransform
. With this you can now cast theTransform
type directly to thePosition
type, and get the position type out of it.It would allow a form of single inheritance, and is fast and very type safe.
Interface's can still be implemented as before, although I'm not sure if structs store a pointer to their member functions? I know a C interface is a struct of function pointers. Not sure how Golang does this.