Skip to content

Instantly share code, notes, and snippets.

@Varriount
Forked from anonymous/generical.nim
Created January 18, 2014 01:35
Show Gist options
  • Save Varriount/8484926 to your computer and use it in GitHub Desktop.
Save Varriount/8484926 to your computer and use it in GitHub Desktop.
# Current styles of generic procedures
# Generic
proc foo[T](a: int, b: T): T =
result = b
var i = 0
while i < a:
result = result+b
# Typedesc
proc foo(T:typedesc, a: int, b: T): T =
result = b
var i = 0
while i < a:
result = result+b
# The generic style procedure can be 'instanciated'
var genProc = foo[int]
# But the Typedesc can't
# However the typedesc supports more calling kinds (can't remember atm)
# So why not make the [] accept more than just types?
var newProc = foo[int, 5] # Only accepts one argument, a number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment