#include #include forall(otype T) struct list { T value; list(T)* next; }; // single polymorphic implementation of each function // overloading reduces need for namespace prefixes forall(otype T) void insert( list(T)** ls, T x ) { list(T)* node = alloc(); // type-inferring alloc (*node){ x, *ls }; // concise constructor syntax *ls = node; } forall(otype T) T head( const list(T)* ls ) { return ls->value; } // use is clear and efficient int main() { list(int)* il = 0; insert( &il, 42 ); // inferred polymorphic T printf("%d\n", head(il)); list(const char*)* sl = 0; insert( &sl, "hello" ); printf("%s\n", head(sl)); }