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

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.

主站蜘蛛池模板: 泽库县| 城口县| 锡林郭勒盟| 介休市| 襄城县| 西青区| 仁化县| 聂荣县| 河北区| 福贡县| 开化县| 桑植县| 张家界市| 横山县| 合水县| 凤翔县| 保山市| 宜城市| 唐河县| 东丰县| 保定市| 措美县| 东莞市| 佳木斯市| 鲜城| 达日县| 安龙县| 龙江县| 普格县| 乌兰察布市| 稷山县| 泌阳县| 都兰县| 阿尔山市| 蒲江县| 台北县| 光山县| 府谷县| 临夏市| 江西省| 吴川市|