I'm trying a little of go programming language.
I'm a excited about the simplicity of the Go, but after playing with it I met some troubles.
1 . I know that Go doesn't support generics and inheritance. Is there any way to implement generic list?
I thinking about using:
type Any interface { }
but how can I check if the value is NULL.
I'm looking for some equivalent implementation to C
struct List {
List* tail;
void* head;
}
Or using algebraic datatype:
data List a = Nil | Cons a (List a)
2 . More advanced requirement would be to make some container for objects with a field of a particular type?
For example in Scala programming language I can type:
val List[Animal { type SuitableFood = Grass} ]
to get a List
of Animals
, which have a member type SuitableFood
which is Grass