Created
April 7, 2021 13:11
-
-
Save tersec/b844ba0bf67a828b2463a2ef81e49740 to your computer and use it in GitHub Desktop.
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 = enum | |
b | |
c | |
K = object | |
y*: string | |
z*: int | |
J = object | |
# K and J aren't nominally-related, but structurally-related types | |
y*: string | |
z*: int | |
D* = object | |
case e: A | |
of b: f*: K | |
of c: g*: J | |
template h(i: D, j: untyped): untyped = | |
if i.e == b: | |
i.f.j | |
else: | |
i.g.j | |
# Deliberately runtime, in principle | |
let | |
m = D(e: b, f: K(y: "foo", z: 3)) | |
n = D(e: c, g: J(y: "bar", z: 7)) | |
echo h(m, y) | |
echo h(m, z) | |
echo h(n, y) | |
echo h(n, z) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment