Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 0.67 KB | None | 0 0
  1. ##############
  2. # Module LIB #
  3. ##############
  4.  
  5. type
  6.   SomeConcept = concept c
  7.     c.myProc() is int
  8.  
  9.   SomeType[T: SomeConcept] = object
  10.     field: T
  11.  
  12. # When this is uncommented, the code compiles and works as expeted.
  13. # proc myProc(c: SomeConcept): int = discard
  14.  
  15. proc init*[T](t: T):SomeType[T] =
  16.   result.field = t
  17.  
  18. proc myProc*[T](t: SomeType[T]) =
  19.   t.field.myProc()
  20.   echo "outer"
  21.  
  22. #####################
  23. # Some other Module #
  24. #####################
  25.  
  26. import lib
  27.  
  28. proc myProc(i: int) =
  29.   echo "inner"
  30.  
  31. var
  32.   i = 5
  33.   t = init(i)
  34.  
  35. myProc(t)
  36.  
  37. # lib.nim(15, 10) Error: type mismatch: got (int)
  38. # but expected one of:
  39. # proc myProc[T](t: SomeType[T])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement