Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Constrained-genericity/Nim/constrained-genericity.nim
Normal file
21
Task/Constrained-genericity/Nim/constrained-genericity.nim
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
type
|
||||
Eatable = concept e
|
||||
eat(e)
|
||||
|
||||
FoodBox[e: Eatable] = seq[e]
|
||||
|
||||
Food = object
|
||||
name: string
|
||||
count: int
|
||||
|
||||
proc eat(x: int) = echo "Eating the int: ", x
|
||||
proc eat(x: Food) = echo "Eating ", x.count, " ", x.name, "s"
|
||||
|
||||
var ints = FoodBox[int](@[1,2,3,4,5])
|
||||
var fs = FoodBox[Food](@[])
|
||||
|
||||
fs.add Food(name: "Hamburger", count: 3)
|
||||
fs.add Food(name: "Cheeseburger", count: 5)
|
||||
|
||||
for f in fs:
|
||||
eat(f)
|
||||
Loading…
Add table
Add a link
Reference in a new issue