[ReasonML] Workshops code
/* 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的更多相关文章
- 用code workshop取代code review
Box Tech Blog » Effective learning through code workshops介绍了Box如何用code workshop而不是code review的形式来改善代 ...
- CV code references
转:http://www.sigvc.org/bbs/thread-72-1-1.html 一.特征提取Feature Extraction: SIFT [1] [Demo program][SI ...
- [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 ...
- Visual Studio Code 代理设置
Visual Studio Code (简称 VS Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器,在十多年的编程经历中,我使用过非常多的的代码编辑器(包括 IDE),例如 Fron ...
- 我们是怎么做Code Review的
前几天看了<Code Review 程序员的寄望与哀伤>,想到我们团队开展Code Review也有2年了,结果还算比较满意,有些经验应该可以和大家一起分享.探讨.我们为什么要推行Code ...
- Code Review 程序员的寄望与哀伤
一个程序员,他写完了代码,在测试环境通过了测试,然后他把它发布到了线上生产环境,但很快就发现在生产环境上出了问题,有潜在的 bug. 事后分析,是生产环境的一些微妙差异,使得这种 bug 场景在线下测 ...
- 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM
刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式——从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ...
- 在Visual Studio Code中配置GO开发环境
一.GO语言安装 详情查看:GO语言下载.安装.配置 二.GoLang插件介绍 对于Visual Studio Code开发工具,有一款优秀的GoLang插件,它的主页为:https://github ...
- 代码的坏味道(14)——重复代码(Duplicate Code)
坏味道--重复代码(Duplicate Code) 重复代码堪称为代码坏味道之首.消除重复代码总是有利无害的. 特征 两个代码片段看上去几乎一样. 问题原因 重复代码通常发生在多个程序员同时在同一程序 ...
随机推荐
- linux学习之多高并发服务器篇(一)
高并发服务器 高并发服务器 并发服务器开发 1.多进程并发服务器 使用多进程并发服务器时要考虑以下几点: 父最大文件描述个数(父进程中需要close关闭accept返回的新文件描述符) 系统内创建进程 ...
- 【习题 8-16 UVA - 1618】Weak Key
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举N[q]和N[r]的位置 因为N[q]是最大值,且N[r]是最小值. 且它们是中间的两个. 枚举这两个可以做到不重复枚举. 然后 ...
- 【转】NPOI使用手册
[转]NPOI使用手册 NPOI使用手册 目录 1.认识NPOI 2. 使用NPOI生成xls文件 2.1 创建基本内容 2.1.1创建Workbook和Sheet 2.1.2创建DocumentSu ...
- 洛谷 P2104 二进制
P2104 二进制 题目描述 小Z最近学会了二进制数,他觉得太小的二进制数太没意思,于是他想对一个巨大二进制数做以下 4 种基础运算: 运算 1:将整个二进制数加 1 运算 2:将整个二进制数减 1 ...
- script指定src后内部代码无效
/********** 无效 ***************/ <script type="text/javascript" src=""> fun ...
- ArcGIS api for javascript——地图配置-定制缩放动画,定制缩放框
描述 本例展示了当用户放大或缩小地图时如何定义地图的动画.zoomDuration和zoomRate是Dojo动画属性,他们确定了动画的duration和帧刷新的rate .这些属性单位是毫秒,zoo ...
- jquery ajax中支持哪些返回类型以及js中判断一个类型常用的方法?
1 jquery ajax中支持哪些返回类型在JQuery中,AJAX有三种实现方式:$.ajax() , $.post , $.get(). 预期服务器返回的数据类型.如果不指定,jQuery 将自 ...
- Ionic2集成ArcGIS JavaScript API.md
1. Ionic同原生ArcGIS JavaScript API结合 1.1. 安装esri-loader 在工程目录下命令行安装: npm install angular2-esri-loader ...
- css3 列表图片hover左右滚动效果
- word中添加Mathtype公式行间距改变问题
转载链接:http://blog.sciencenet.cn/home.php?mod=space&uid=471807&do=blog&id=616838 最近碰到在word ...