-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathC3-linearization.edh
59 lines (41 loc) · 1.06 KB
/
C3-linearization.edh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# https://en.wikipedia.org/wiki/C3_linearization
# %%
class O pass
class A extends O
class B extends O
class C extends O
class D extends O
class E extends O
class K1 extends ( A, B, C )
class K2 extends ( D, B, E )
class K3 extends ( D, A )
class Z extends ( K1, K2, K3 )
# %%
Z.mro
# unlike other object systems (e.g. in Python), where all member attributes
# (including methods) collapse into a single end object instance, in Edh an
# object is composed of a self instance and all super object instances
# strictly corresponding to mro of its class, and each such super instance
# satisfies the same rule if viewed alone, while at the same time shared
# super class induces shared object, there'll be no duplication of super
# instances.
# %%
z = Z()
supers( z )
# %%
# a specific super instance can be obtained via pattern matching:
case z of { { K2: k2 } } -> k2
# %%
# check a super instance alone
K2.mro
# %%
supers( k2 )
# %%
# check a super instance shared
{
(
case z of { { O: z's'o } } -> z's'o
) is (
case k2 of { { O: k2's'o } } -> k2's'o
)
}