/* list of strings */
let _ = ["example-1", "example-2", "example-3"]; /* Array of strings */
let _ = [|"example-1", "example-2", "example-3"|]; /* Stating the type of a Reason record */
type event = {
location: string,
years: list int
}; /* Making a Reason record */
{location: "Bratislava", years: [2017, 2018]}; /** Our first Reason function, already?
(Use ^ to join strings together) */
let rock song => Js.log ("We're all rocking to " ^ song); /* Manually specifying types */
/* Use {j| ... |j} to interpolate strings */
let rock (song: string) (times: int) :string =>
{j|Rocked out to $(song) $(string_of_int times) times|j}; rock "Nad Tatrou sa blýska" 1; /* Invoke our function! */ /* Function with labelled arguments */
let rockLabelled ::songName ::times =>
{j|Rocked out to $(song) $(string_of_int times) times|j}; rockLabelled songName::"Nad Tatrou sa blýska" times::1; /* Invoke our function with labelled arguments! */ /* Making a ReasonReact component */
MyComponent.make foo::bar children::[] () /* Making a ReasonReact component with JSX */
<MyComponent foo={bar} /> /* A variant animal type */
type animal =
| Dog
| Cat
| Bird; /* Pattern matching our custom animal variant type */
let feed pet =>
switch pet {
| Dog => "woof"
| Cat => "meow"
| Bird => "chirp"
}; /** Destructuring combines code flow and extracts values at the same time,
let's do it here with a list of strings */
let names = ["Daniel", "Jared", "Sean"]; switch names {
| [] => "No names!"
| [personOne] => "One person in list, named " ^ personOne
| [personOne, personTwo] => "Two people in list, both " ^ personOne ^ " and " ^ personTwo
| [personOne, _, personThree, ...rest] =>
"At least three people in the list, but we picked out " ^ personOne ^ " and " ^ personThree
}; /* Destructuring a record type */
type event = {
location: string,
years: list int
}; let event = {location: "Bratislava", years: [2017, 2018]}; let message = switch event {
| {location: "Bratislava", years} =>
"This event was in Bratislava for " ^ (string_of_int (List.length years))
| {location, years: [2018, 2019]} => "This event was in " ^ location ^ " for 2018 and 2019"
| event => "This is a generic event"
}; /* Binding to JavaScript libraries */
/* From https://github.com/reasonml-community/bs-moment/blob/master/src/MomentRe.re */ external alert : string => unit = "alert" [@@bs.val];
external imul : int => int => int = "Math.imul" [@@bs.val];
external reverse : array 'someKind => array 'someKind = "" [@@bs.send];
let identity: 'a => 'a => 'a = [%bs.raw {|function(x,y){/* Dangerous JavaScript! */ return x < y}|}]; alert "Bound successfully!";
imul 1 2;
reverse [|1, 2, 3|];
identity 1 2;

[ReasonML] Workshops code的更多相关文章

  1. 用code workshop取代code review

    Box Tech Blog » Effective learning through code workshops介绍了Box如何用code workshop而不是code review的形式来改善代 ...

  2. CV code references

    转:http://www.sigvc.org/bbs/thread-72-1-1.html 一.特征提取Feature Extraction:   SIFT [1] [Demo program][SI ...

  3. [REASONML] Using Javascript npm package from REASON

    For example, we want to use moment.js inside our ReasonML code. What we can do is create a module fi ...

  4. Visual Studio Code 代理设置

    Visual Studio Code (简称 VS Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器,在十多年的编程经历中,我使用过非常多的的代码编辑器(包括 IDE),例如 Fron ...

  5. 我们是怎么做Code Review的

    前几天看了<Code Review 程序员的寄望与哀伤>,想到我们团队开展Code Review也有2年了,结果还算比较满意,有些经验应该可以和大家一起分享.探讨.我们为什么要推行Code ...

  6. Code Review 程序员的寄望与哀伤

    一个程序员,他写完了代码,在测试环境通过了测试,然后他把它发布到了线上生产环境,但很快就发现在生产环境上出了问题,有潜在的 bug. 事后分析,是生产环境的一些微妙差异,使得这种 bug 场景在线下测 ...

  7. 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM

    刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式——从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ...

  8. 在Visual Studio Code中配置GO开发环境

    一.GO语言安装 详情查看:GO语言下载.安装.配置 二.GoLang插件介绍 对于Visual Studio Code开发工具,有一款优秀的GoLang插件,它的主页为:https://github ...

  9. 代码的坏味道(14)——重复代码(Duplicate Code)

    坏味道--重复代码(Duplicate Code) 重复代码堪称为代码坏味道之首.消除重复代码总是有利无害的. 特征 两个代码片段看上去几乎一样. 问题原因 重复代码通常发生在多个程序员同时在同一程序 ...

随机推荐

  1. HDU-1035 Robot Motion 模拟问题(水题)

    题目链接:https://cn.vjudge.net/problem/HDU-1035 水题 代码 #include <cstdio> #include <map> int h ...

  2. CF402E Strictly Positive Matrix(矩阵,强联通分量)

    题意 给定一个 n∗n 的矩阵 A,每个元素都非负判断是否存在一个整数 k 使得 A^k 的所有元素 >0 n≤2000(矩阵中[i][i]保证为1) 题解 考虑矩阵$A*A$的意义 ,设得到的 ...

  3. hibernate 不与数据库对应的注解

    @Transient          此注解必须写到get方法上

  4. GIMP类似于PhotoShop的开源免费软件

    首先我们先看看他的界面如何,都有哪些功能!而且它支持多种平台,可以在MacOS.Windows.Linux操作系统上使用.非常值得推荐! ​ 1.官方地址下载地址: https://www.gimp. ...

  5. Zookeeper入门:基本概念、5项配置、启动

    起源 最早接触Zookeeper,是在学习Hadoop权威指南这本书的时候,印象中是Hadoop项目的一个子工程.      最近,项目中需要用到"分布式锁".      之前,在 ...

  6. scala细节

    在高版本中,scala使用了自己的String,而不是java.lang.String 字符串转数字:"33.4".toDouble    "33.4".toF ...

  7. Android带索引联系人列表

    网上Android联系人列表的样例也非常多,都和微信的联系人差点儿相同,因为项目用到了联系人列表索引功能(产品把字母item给去掉了),只是也还是好实现.这里我也来分享分享我的实现,免得以后忘了.那先 ...

  8. HDU3265 Examining the Rooms【stirling数】

    题目链接: http://acm.hdu.edu.cn/showproblem.php? pid=3625 题目大意: 有N个房间,每一个房间的要是随机放在某个房间内,概率同样.有K次炸门的机会. 求 ...

  9. Android程序猿自己动手制作.9.png图片

    1:怎样制作9.png图片素材: 打开SDK工具文件夹下: draw9patch.zip  解压执行draw9patch.bat.有的直接搜索会有:draw9patch.bat. 双击执行后,例如以下 ...

  10. 优化时序之补全if else

    时序优化中重要的一项就是提高模块的最高工作频率,工作频率由关键路径决定,通常的提高工作频率的步骤是:利用时序分析工具找到关键路径,分析关键路径主要延迟是布线延迟还是逻辑延迟,然后轮番十八般武器,如果是 ...