Skip to content

Commit 059022e

Browse files
authored
New blog post (#343)
* New blog post * Check in BlogData.res changes
1 parent fc16f2d commit 059022e

File tree

3 files changed

+169
-0
lines changed

3 files changed

+169
-0
lines changed

_blogposts/2021-05-07-release-9-1.mdx

+164
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
---
2+
author: rescript-team
3+
date: "2021-05-07"
4+
previewImg: https://res.cloudinary.com/dmm9n7v9f/image/upload/v1620295955/Reason%20Association/rescript-lang.org/compiler_release_9_1_lu5oac.jpg
5+
title: ReScript 9.1
6+
badge: release
7+
description: |
8+
Featuring a new npm package, a CLI revamp, polymorphic variant interop and object cleanup.
9+
---
10+
11+
## Exciting Improvements in ReScript 9.1
12+
13+
Our recent few releases of ReScript contains [lots of improvements](https://github.com/rescript-lang/rescript-compiler/blob/3134392a364b70c9c172aa6c1dbaa1ac6580265d/Changes.md#91), among which are a few standout features we'd like to further promote. Hope you're as excited as we are about these! It goes without saying, our [updated editor plugin](https://forum.rescript-lang.org/t/ann-rescript-vscode-1-1-1-released/1542/3) works with the new releases.
14+
15+
### New NPM Package
16+
17+
We've finally moved from [bs-platform](https://www.npmjs.com/package/bs-platform) to [rescript](https://www.npmjs.com/package/rescript)!
18+
19+
This is mostly just a long overdue name change; the package's virtually identical. Apart from the renaming of our CLI.
20+
21+
### CLI Cleanup
22+
23+
We took the occasion of the NPM package move to also unify the binaries `bsc`, `bsb` and their various commands into a single `rescript` command:
24+
25+
```sh
26+
❯ rescript -help
27+
Available flags
28+
-v, -version display version number
29+
-h, -help display help
30+
Subcommands:
31+
build
32+
clean
33+
format
34+
convert
35+
help
36+
Run rescript subcommand -h for more details,
37+
For example:
38+
rescript build -h
39+
rescript format -h
40+
The default `rescript` is equivalent to `rescript build` subcommand
41+
```
42+
43+
Here's a table of translation, if you're upgrading your script that is currently using `bsc` and `bsb`:
44+
- `bsc -format myFile.res`: `rescript format myFile.res`
45+
- `bsb`: `rescript build` \*
46+
- `bsb -make-world`: `rescript build -with-deps` \*
47+
- `bsb -w`: `rescript build -w`
48+
- `bsb -w -make-world`: `rescript build -w -with-deps` \*
49+
50+
\* **However**, we've gone even further to improve your experience; in most cases you won't need to invoke `build`, nor `-with-deps` anymore! Not only is `rescript` an alias to `rescript build`, it also smartly detects whether your dependencies are already built; if not, it builds them automatically.
51+
52+
This means that you can ditch your old `-make-world` (now the explicit `-with-deps` flag, for edge-case explicit usages). Just call `rescript` and everything including dependencies will always be built! As performance is our highest priority, we've ensured that such extra detections does not slow down the build.
53+
54+
### Polymorphic Variants for Numbers and Strings
55+
56+
*Drumrolls*
57+
- Poly variants like `#1`, `#42` compile to JavaScript numbers.
58+
- Poly variants like `#hello`, `#world` compile to JavaScript Strings.
59+
60+
This is a feature many of you were probably waiting for. Now you can interop with a JavaScript value that's a limited set of numbers or strings:
61+
62+
<CodeTab labels={["ReScript", "JS Output"]}>
63+
64+
```res
65+
let secret = #42
66+
67+
// optional type annotation, for documentation
68+
type t = [#1 | #3 | #5 ]
69+
70+
// enjoy the pattern matching
71+
let test = (arg: t) => {
72+
switch arg {
73+
| #1 | #3 => "hello"
74+
| #5 => "world"
75+
}
76+
}
77+
```
78+
79+
```js
80+
var secret = 42;
81+
82+
function test(arg) {
83+
if (arg === 5) {
84+
return "world";
85+
} else {
86+
return "hello";
87+
}
88+
}
89+
```
90+
91+
</CodeTab>
92+
93+
But wait, **there's more**. We allow safely coercing these poly variants to `int`s or `string`s even at the ReScript side:
94+
95+
<CodeTab labels={["ReScript", "JS Output"]}>
96+
97+
```res
98+
let test2 = (arg: [#1 | #3 | #5]) => {
99+
(arg :> int)
100+
}
101+
102+
let test3 = (arg: option<[#1 | #3 | #5]>) => {
103+
(arg :> option<int>)
104+
}
105+
106+
Js.log(test2(#1))
107+
Js.log(test3(Some(#3)))
108+
```
109+
110+
```js
111+
function test2(arg) {
112+
return arg;
113+
}
114+
115+
function test3(arg) {
116+
return arg;
117+
}
118+
119+
console.log(1);
120+
console.log(3);
121+
```
122+
123+
</CodeTab>
124+
125+
As usual, check the output tabs: there's no runtime cost. Time to upgrade some interop!
126+
127+
### Object Cleanup
128+
129+
Our objects had various constraints due to legacy reasons; we've managed to clean them up, and expose the UX that they deserve:
130+
131+
- `Js.t<{"x": int}>` is now simply `{"x": int}`. Existing code using `Js.t` still work; it's now a no-op. Our `rescript format` will also format them away.
132+
- You can now use object type spread:
133+
```
134+
type point2d = {
135+
"x": float,
136+
"y": float,
137+
}
138+
type point3d = {
139+
...point2d,
140+
"z": float,
141+
}
142+
```
143+
144+
The cleanup also allowed us to unlock very exciting ideas. For example, [this one](https://forum.rescript-lang.org/t/rfc-more-general-type-checking-for-structural-typings/1485).
145+
146+
## What's Next?
147+
148+
First class unicode support! Expect being able to write the following:
149+
150+
```res
151+
let helloUnicode = (x) =>{
152+
switch x {
153+
| '❤️' => "ReScript is awesome"
154+
| 'Σ' => "Math is fun"
155+
| _ => "Lots of unicode"
156+
}
157+
}
158+
```
159+
160+
## Conclusion
161+
162+
Don't miss our various other improvements in [our changelog](https://github.com/rescript-lang/rescript-compiler/blob/3134392a364b70c9c172aa6c1dbaa1ac6580265d/Changes.md#91). As always we try to keep our changes performant, lean and robust. We hope you'll enjoy these.
163+
164+
See you next time!

src/BlogData.mjs

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33

44
var data = [
5+
[
6+
"release-9-1",
7+
"2021-05-07-release-9-1"
8+
],
59
[
610
"rescript-association-rebranding",
711
"2021-03-03-rescript-association-rebranding"

src/BlogData.res

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ type pair = {slug: string, fullslug: string}
33

44
let data = Js.Array2.map(
55
[
6+
("release-9-1", "2021-05-07-release-9-1"),
67
("rescript-association-rebranding", "2021-03-03-rescript-association-rebranding"),
78
("release-9-0", "2021-02-09-release-9-0"),
89
("release-8-3-pt2", "2020-09-25-release-8-3-2"),

0 commit comments

Comments
 (0)