官术网_书友最值得收藏!

Using Try Reason

Reason provides a fantastic resource for learners: an online Reason-to-JavaScript compiler and evaluator. To access it, go to the Reason website and click Try in the navigation bar at the top. You can use it to quickly try out different ideas.

Let's run through a quick example using Try Reason to get our bearings. Type in the example code from src/Ch01/Ch01_Demo.re into the Reason section of the Try Reason web app. Now add the following line after that:

let bob = makePerson(1, "Bob");

Now if you examine the output JS, you should see that the following changes have been made:

  • Types have been stripped away
  • Records have been transformed into arrays without field names (records are roughly like C structs or JavaScript objects)
  • Every declared value is explicitly exported (made public)

Note that we have purposely introduced very little actual Reason syntax in this chapter. If you are curious to explore the syntax (which is very similar to JavaScript at its core), it's best if you explore the excellent Reason website documentation. Since the focus of this book is type-driven development, in the upcoming chapters we will introduce all the syntax we will need and discuss its impact on our understanding of the code.

主站蜘蛛池模板: 工布江达县| 喜德县| 连云港市| 西藏| 北海市| 隆林| 磐石市| 敦化市| 八宿县| 寿阳县| 江山市| 日照市| 惠州市| 长沙市| 景德镇市| 新化县| 饶平县| 景德镇市| 仙游县| 清流县| 房产| 明星| 丰镇市| 台中市| 墨竹工卡县| 安阳市| 富阳市| 理塘县| 济阳县| 德令哈市| 昌都县| 永康市| 江孜县| 上杭县| 昭通市| 寿宁县| 泸西县| 云霄县| 东乌| 微山县| 横山县|