Created
June 15, 2015 13:40
-
-
Save ozra/b66b153afe65e602c3da to your computer and use it in GitHub Desktop.
Tinkering with Nim OOP - what's wrong?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type | |
A = ref A_obj | |
A_obj = object {.inheritable} | |
forward_deps: seq[A] | |
B[T] = ref B_obj[T] | |
B_obj[T] = object of A_obj | |
values: seq[T] | |
proc new_B–ish[T](): T = | |
new result | |
result.values = @[] | |
result.forward_deps = @[] | |
# May be added at a later time | |
type | |
C_obj[T] = object of B_obj[T] | |
C[T] = ref C_obj[T] | |
proc new_C[T](): C[T] = | |
result = new_B–ish[C[T]]() | |
# Does other things too... | |
# May be added at a later time | |
type | |
D[T1, T2] = ref object of B_obj[T1] | |
s1: ptr T1 | |
s2: ptr T2 | |
proc `*`[T1, T2](in_s1: B[T1], in_s2: B[T2]): D[T1, T2] = | |
result = new_B–ish[D[T1, T2]] | |
# other stuff happens here... | |
method do_process[T1, T2](o: D[T1, T2]) = | |
while true: | |
# Does stuff... | |
break | |
# Test instantiation | |
var c_thing = new_C[float64]() | |
var other_thing = c_thing * c_thing | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment