Guest User

Untitled

a guest
Apr 24th, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 0.61 KB | None | 0 0
  1. type
  2.     BaseType = ref object of RootObj
  3.         a: int
  4.  
  5.     BContainer = tuple
  6.       b: int
  7.  
  8.     MyType = ref object of BaseType
  9.  
  10. method Yay[M](obj:BaseType):seq[M] {.base.} =
  11.     echo "Base Yay"
  12.  
  13. method Yay[BContainer](obj:MyType):seq[BContainer] =
  14.     echo "MyType Yay"
  15.     return @[(10,)]
  16.  
  17. proc DoSomething[T,M](obj:var T,genType:M) =
  18.   var yay = obj.Yay()
  19.   echo yay
  20.  
  21.  
  22. var b = new MyType
  23. DoSomething(b, (1,))
  24.  
  25.  
  26. # dstn.nim(22, 12) template/generic instantiation from here
  27. # dstn.nim(18, 16) template/generic instantiation from here
  28. # dstn.nim(13, 12) Error: cannot instantiate: 'BContainer'
Add Comment
Please, Sign In to add comment