diff --git a/content/procs.md b/content/procs.md index 93a9d6b..e51a943 100644 --- a/content/procs.md +++ b/content/procs.md @@ -63,6 +63,21 @@ proc `^&*^@%`(a, b: string): string = assert("foo" ^&*^@% "bar" == "fr") ``` +## Generic Functions -- operators -- generics \ No newline at end of file + +Generic functions are like C++'s templates and allow for the same statically checked duck-typing semantics as templates. + +``` nimrod +# Not really good idea for obvious reasons +let zero = "" +proc `+`(a, b: string): string = + a & b + +proc `*`[T, I](a: T, b: int): T = + result = zero + for i in 0..b: + result = result + a + +assert("a" * 10 == "aaaaaaaaaaa") +``` \ No newline at end of file