Last active
April 29, 2019 02:43
-
-
Save susisu/6b0a2a8ccccb28c8f6908e3d9df3dc40 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
const ref = <T>(f: (x: T) => T) => { | |
const r = { val: f }; | |
return () => r; | |
}; | |
const id = <T>(x: T) => x; | |
// r: <T>() => { val: (x: T) => T } | |
const r = ref(id); | |
// unsafe instantiations of r | |
const r1 = r<number>(); | |
const r2 = r<string>(); | |
// update r1.val with a function specific to numbers | |
r1.val = (x: number) => x * 2; | |
// using r2.val will cause runtime failure | |
r2.val("foo"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment