jan_flanders

Untitled

Nov 22nd, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. The haxe compiler uses type inference to infer (deduce) the type from values you assign to a variable.
  2. This relieves you from the burden to strongly type all your variables without losing strong typing.
  3.  
  4. For example, the following code:
  5.  
  6. var f = 10.5;
  7. var s = "foo";
  8. var arr = ["hello", "world"];
  9.  
  10. will be compiled as if you had written:
  11.  
  12. var f:Float = 10.5;
  13. var s:String = "foo";
  14. var arr:Array<String> = ["hello", "world"];
  15.  
  16. (Mostly) for debugging purposes, you can check at compile time which type the compiler deduced, by using the special identifier '$type'.
  17. We'll use it in the rest of this explanation to show how the compiler infers types.
Advertisement
Add Comment
Please, Sign In to add comment