-- tests/generics.cat -- generic type parameters (erasure model). -- -- `class Box` / `interface Container` accept a `` parameter -- list. Parameter names are compile-time only (erased at runtime), so a -- generic declaration is an ordinary class/interface tagged with its -- parameters in `__generic` -- structural, like the rest of the typing. class Box function init(self, v) self.v = v end function get(self) return self.v end end interface Container function size(self) end end class Vec implements Container function size(self) return 3 end end local b = Box("hi") print("box:", b.get(), b::__generic) local v = Vec() print("vec:", v.size(), v is Container) -- two parameters class Pair function init(self, k, val) self.k = k self.val = val end end local p = Pair("x", 9) print("pair:", p.k, p.val, p::__generic)