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

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.

主站蜘蛛池模板: 凤台县| 涪陵区| 张家界市| 临汾市| 乌拉特前旗| 高青县| 普格县| 外汇| 福泉市| 竹山县| 靖江市| 元江| 大厂| 盐亭县| 济南市| 昌吉市| 崇仁县| 吐鲁番市| 西畴县| 广昌县| 天峨县| 广宗县| 九寨沟县| 黑山县| 墨玉县| 监利县| 南通市| 黔江区| 霍城县| 洪泽县| 常山县| 阳西县| 兴义市| 台湾省| 湾仔区| 桃园市| 吉水县| 昭平县| 靖江市| 武安市| 杭锦后旗|