Prev | Current Page 80 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

5;
var str:String = ???The quick brown fox.???;
trace(flt);
trace(str);
}
}
Now, compile the code using the following .hxml content:
-neko variableassignment.n
-main VariableAssignment
When you execute the code, you should be presented with the following output:
VariableAssignment.hx:7: 10.5
VariableAssignment.hx:8: The quick brown fox.
When the code is compiled, the compiler can compare the values passed to the variables with the types
specified for those variables. The trace function provides a means to convert most data types to a string
representational format, which it then writes to the console.
The problem that may arise is if you do not know the type of information that will be stored inside a
variable. What if you had created a program that was to respond to data provided by an outside source,
so the information you wish to store in a variable could not be decided until run time?
The answer to this is to use type inference.
Type Inference
Type inference is the process of letting the compiler guess the types at compile time, in order to provide
strict typing without having to specify types for every variable.


Pages:
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92