Created
September 9, 2015 20:26
-
-
Save sinelaw/f1c47f9f2562e16de817 to your computer and use it in GitHub Desktop.
type case simulated using polymorphic sums
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
foo :: +{ Num : Number, Str : String | r } -> Number | |
function foo(x) { | |
if (typeof x == Number) { .. x is a number here! ...; return 0 } | |
else if (typeof x == String) { .. a string here ..; return 1 } | |
else { .. } | |
} | |
\case x of | |
Num n -> ... ; 0 | |
Str s -> ... ; 1 | |
_ -> ... | |
addOne :: +{ Num : Number } -> +{ Num : Number } | |
function addOne(x) { return x + 1; } | |
34 :: forall r. +{ Num : Number | r } | |
'bla' :: forall t. +{ Str : String | t } | |
foo(34) ===> here instantiated to: foo :: +{ Num : Number, Str : String } -> Number , and 34 :: +{ Num : Number, Str : String } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment