- 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.
- Python科學(xué)計(jì)算(第2版)
- JavaScript修煉之道
- Visual Basic程序開(kāi)發(fā)(學(xué)習(xí)筆記)
- Java從入門(mén)到精通(第4版)
- Visual Basic程序設(shè)計(jì)與應(yīng)用實(shí)踐教程
- Android Native Development Kit Cookbook
- WebRTC技術(shù)詳解:從0到1構(gòu)建多人視頻會(huì)議系統(tǒng)
- Apache Kafka Quick Start Guide
- C# 8.0核心技術(shù)指南(原書(shū)第8版)
- 從零開(kāi)始學(xué)C#
- 用戶體驗(yàn)可視化指南
- Scratch3.0趣味編程動(dòng)手玩:比賽訓(xùn)練營(yíng)
- Django實(shí)戰(zhàn):Python Web典型模塊與項(xiàng)目開(kāi)發(fā)
- 基于GPU加速的計(jì)算機(jī)視覺(jué)編程:使用OpenCV和CUDA實(shí)時(shí)處理復(fù)雜圖像數(shù)據(jù)
- 虛擬現(xiàn)實(shí)建模與編程(SketchUp+OSG開(kāi)發(fā)技術(shù))