Skip to content

Commit 9c0fb10

Browse files
authored
feat: add typo checker (#31)
* feat: add typo checker * fix: typos * fix: `@map` -> `@immut/sorted_map` * fix: add `_typos.toml`
1 parent 75bc751 commit 9c0fb10

File tree

5 files changed

+35
-10
lines changed

5 files changed

+35
-10
lines changed

.github/workflows/typo.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Check Typos
2+
on:
3+
pull_request
4+
5+
jobs:
6+
typo-check:
7+
runs-on: ubuntu-latest
8+
timeout-minutes: 10
9+
env:
10+
FORCE_COLOR: 1
11+
TYPOS_VERSION: v1.19.0
12+
steps:
13+
- name: download typos
14+
run: curl -LsSf https://github.com/crate-ci/typos/releases/download/$TYPOS_VERSION/typos-$TYPOS_VERSION-x86_64-unknown-linux-musl.tar.gz | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin
15+
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
with:
19+
ref: ${{ github.event.pull_request.head.sha }}
20+
21+
- name: check typos
22+
run: typos

_typos.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[default.extend-words]
2+
# **W**ine **I**s **N**ot an **E**mulator
3+
ot = "ot"

docs/01-program-design.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,6 @@ It is recommended to adopt a TDD workflow, namely,
107107
3. Write the test cases
108108
4. Implement the program
109109

110-
Modern softwares are typically vast in scale, making TDD a reliable workflow for their development. By creating test cases in advance, developers can efficiently identify and rectify potential errors at an early stage, while also ensuring the seamless integration of new functions without disrupting existing ones.
110+
Modern software products are typically vast in scale, making TDD a reliable workflow for their development. By creating test cases in advance, developers can efficiently identify and rectify potential errors at an early stage, while also ensuring the seamless integration of new functions without disrupting existing ones.
111111

112112
Quiz: For some abnormal inputs, the sample program for the water bottles problem may fail. Can you identify them? (Hint: In MoonBit, the range of `Int` values is $-2^{31}$ to $2^{31} - 1$.)

docs/03-functions-lists-recursion.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
```moonbit
55
let pi = 3.1415
66
7-
fn put(map: @map.Map[Int, Int64], num: Int, result: Int64) -> @map.Map[Int, Int64] {
7+
fn put(map: @immut/sorted_map.Map[Int, Int64], num: Int, result: Int64) -> @immut/sorted_map.Map[Int, Int64] {
88
map.insert(num, result)
99
}
1010
11-
fn get(map: @map.Map[Int, Int64], num: Int) -> Option[Int64] {
11+
fn get(map: @immut/sorted_map.Map[Int, Int64], num: Int) -> Option[Int64] {
1212
map.lookup(num)
1313
}
1414
15-
fn make() -> @map.Map[Int, Int64] {
16-
@map.empty()
15+
fn make() -> @immut/sorted_map.Map[Int, Int64] {
16+
@immut/sorted_map.empty()
1717
}
1818
1919
```
@@ -264,7 +264,7 @@ The following examples help deepen our understanding of lists.
264264
- `Cons(1, 2)`: `2` itself is not a list.
265265
- `Cons(1, Cons(Nil, Nil))`: Items are of different types.
266266

267-
Like `Option[T]`, the list type `List[T]` is also genereic.
267+
Like `Option[T]`, the list type `List[T]` is also generic.
268268

269269
- A list of integers is of type `List[Int]`.
270270
- A list of strings is of type `List[String]`.
@@ -555,13 +555,13 @@ fn get(map: IntMap, num: Int) -> Option[Int64] // Retrieve
555555

556556
In other words, we should be able to perform the following operations using an `IntMap`: create an empty map, insert a key-value pair into it, and look up the value corresponding to a given key.
557557

558-
Thanks to our paradigm of modular programming, we only need to care about the interfaces rather than the specific implementation. Therefore, there are many siutable data structures in MoonBit's standard library. In this example, we will use `@map.Map[Int, Int64]`, but we can easily replace it with another data structure, as long as it implements the interfaces we need.
558+
Thanks to our paradigm of modular programming, we only need to care about the interfaces rather than the specific implementation. Therefore, there are many suitable data structures in MoonBit's standard library. In this example, we will use `@immut/sorted_map.Map[Int, Int64]`, but we can easily replace it with another data structure, as long as it implements the interfaces we need.
559559

560560
In the top-down implementation, before each computation, we first check if our desired result has been cached: if it does, we can simply use the result; if it doesn't, we calculate the result and store it in the data structure.
561561

562562
```moonbit expr
563563
fn fib1(num: Int) -> Int64 {
564-
fn aux(num: Int, map: @map.Map[Int, Int64]) -> (Int64, @map.Map[Int, Int64]) {
564+
fn aux(num: Int, map: @immut/sorted_map.Map[Int, Int64]) -> (Int64, @immut/sorted_map.Map[Int, Int64]) {
565565
match get(map, num) {
566566
Some(result) => (result, map)
567567
None => {
@@ -608,7 +608,7 @@ In the bottom-up implementation, we typically start from the smallest subproblem
608608

609609
```moonbit expr
610610
fn fib2(num: Int) -> Int64 {
611-
fn aux(n: Int, map: @map.Map[Int, Int64]) -> Int64 {
611+
fn aux(n: Int, map: @immut/sorted_map.Map[Int, Int64]) -> Int64 {
612612
let result = get_or_else(get(map, n - 1), 1L) +
613613
get_or_else(get(map, n - 2), 1L)
614614
if n == num { result }

docs/04-tuples-structs-enums.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ $$
317317
\end{array}
318318
$$
319319

320-
The definition of `List[Int]` tells us that a list of intergers is either an empty list or composed of an integer with a sublist. An empty list is isomorphic to the Unit type, so it can be expressed as `1 + Int * List`. As `List` is recursive, it can be substituted with `1 + Int * 1 + Int * List`. Applying the associative law of multiplication, we get `1 + Int * (1 + Int * List)`. Continuing the substitution and simplification, we find that the set of integer lists is a distinguishable union of a single-value set, an integer set, two integer sets, and even an infinite Cartesian product of integer sets. This corresponds with reality.
320+
The definition of `List[Int]` tells us that a list of integers is either an empty list or composed of an integer with a sublist. An empty list is isomorphic to the Unit type, so it can be expressed as `1 + Int * List`. As `List` is recursive, it can be substituted with `1 + Int * 1 + Int * List`. Applying the associative law of multiplication, we get `1 + Int * (1 + Int * List)`. Continuing the substitution and simplification, we find that the set of integer lists is a distinguishable union of a single-value set, an integer set, two integer sets, and even an infinite Cartesian product of integer sets. This corresponds with reality.
321321

322322
## Summary
323323

0 commit comments

Comments
 (0)