Created
April 20, 2016 22:51
-
-
Save asolove/cdd3a0e62fe2f757179f8bac8e01e349 to your computer and use it in GitHub Desktop.
Subtyping polymorphism!
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
// @flow | |
type Foo<A> = { n: number, extra: A }; | |
type Foo2 = Foo<{s: string}>; | |
type Bar<A> = { foo: Foo<A> }; | |
type Bar2 = { foo: Foo2 }; | |
function getBarN(bar: Bar){ return bar.foo.n } | |
function getBarS(bar: Bar2){ return bar.foo.extra.s } | |
let bar2: Bar2 = { foo: { n: 2, extra: {s: ""} }}; | |
getBarN(bar2); | |
getBarS(bar2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment