- Learn Type:Driven Development
- Yawar Amin Kamon Ayeva
- 239字
- 2021-07-02 14:41:26
Understanding type erasure
To concretely grasp the effect of static/dynamic separation, let's look at type erasure, which is something that happens when we compile the preceding code to JavaScript. The following is the output with all redundant comments removed:
// src/Ch02/Ch02_Demo.bs.js
var bob = [1, "Bob"];
var acmeCo_002 = [bob, 0];
var acmeCo = [1, "Acme Co.", acmeCo_002];
As we mentioned earlier, BuckleScript compiles Reason record types into JavaScript arrays with the corresponding number of elements. BuckleScript, in fact, performs quite a number of optimizations for you. Some of these come from its underlying OCaml compiler technology, which has been developed since the 1990s, but other things are quite unique in the world of language-to-JavaScript compilers.
Notice that BuckleScript has wiped out both the type definitions and has output only the minimum number of values it actually needs for runtime. The important thing to understand here is that all the output values follow the laws introduced by their corresponding types; for example, the Bob value, of type person, can only be an array with two elements (a number and a string, corresponding to the two fields in the person record), and the acmeCo value can only be an array with three elements of the correct types. Anything else is impossible – with a mathematical degree of certainty – even in output JavaScript code, because code that doesn't pass the typing rules (that is, doesn't typecheck) would not even compile.
- JSP網絡編程(學習筆記)
- C和C++安全編碼(原書第2版)
- Mastering Spring MVC 4
- Visual Basic程序設計(第3版):學習指導與練習
- RTC程序設計:實時音視頻權威指南
- 數據結構習題解析與實驗指導
- 執劍而舞:用代碼創作藝術
- Visualforce Developer’s guide
- .NET Standard 2.0 Cookbook
- Beginning C++ Game Programming
- Android移動應用開發項目教程
- 精通Spring:Java Web開發與Spring Boot高級功能
- 計算語言學導論
- 現代C++語言核心特性解析
- Node.js Web Development