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

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.

主站蜘蛛池模板: 沙洋县| 汶上县| 井研县| 临夏市| 云阳县| 获嘉县| 根河市| 平安县| 萝北县| 河西区| 大渡口区| 许昌市| 平定县| 郯城县| 绥江县| 南昌市| 伊吾县| 南靖县| 弥勒县| 阜宁县| 安多县| 伊春市| 古田县| 新沂市| 汕尾市| 滁州市| 南宁市| 汶川县| 宁蒗| 屯留县| 肃宁县| 安庆市| 平武县| 桑日县| 苍梧县| 施秉县| 铜梁县| 太康县| 香港 | 南部县| 榆树市|