From 85110dd244c9e2ecc84424cf11244d8ede26840d Mon Sep 17 00:00:00 2001 From: Andrew Morris Date: Tue, 15 Aug 2023 16:46:51 +1000 Subject: [PATCH] Update structuralComparison.ts --- .../files/root/tutorial/structuralComparison.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/website/src/playground/files/root/tutorial/structuralComparison.ts b/website/src/playground/files/root/tutorial/structuralComparison.ts index 241d8210..0e1b9aaf 100644 --- a/website/src/playground/files/root/tutorial/structuralComparison.ts +++ b/website/src/playground/files/root/tutorial/structuralComparison.ts @@ -2,15 +2,19 @@ // identity. export default function () { - return vec3(-5, 7, 12) === vec3(-5, 7, 12); + return new Vec3(-5, 7, 12) === new Vec3(-5, 7, 12); // JavaScript: false // ValueScript: true } -function vec3(x: number, y: number, z: number) { - return { x, y, z }; +class Vec3 { + constructor(public x: number, public y: number, public z: number) {} } +// There's a lot going on to make this work for the underlying functions being compared, especially +// since functions can reference each other recursively. The underlying mechanism is content +// hashing. Check the source or open an issue if you'd like to know more. + // Caveat: // - TypeScript will emit an error for expressions like `[a, b] === [c, d]`. //