Skip to content

Commit

Permalink
Merge pull request #50 from tonyfettes/main
Browse files Browse the repository at this point in the history
fix: remove the usage of List::[..]
  • Loading branch information
tonyfettes authored Sep 9, 2024
2 parents 7048bc1 + 7643902 commit f1af1bd
Show file tree
Hide file tree
Showing 19 changed files with 541 additions and 211 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/mdlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ jobs:
- name: Install mdlint
run: npm install -g @moonbit/markdown-linter

- name: Install moonBit
- name: Install MoonBit
run: /bin/bash -c "$(curl -fsSL https://cli.moonbitlang.com/ubuntu_x86_64_moon_setup.sh)"

- uses: DavidAnson/markdownlint-cli2-action@v16
with:
globs: 'docs/*.md'

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v43
Expand Down
6 changes: 6 additions & 0 deletions .markdownlint.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"default": true,
"MD013": false,
"MD033": false,
"MD045": false
}
34 changes: 17 additions & 17 deletions docs/00-course-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ The course is suitable for a wide audience, from programming beginners to experi

## Course Outline

| Chapter | Topic | Slides | Video | Code Repository |
| :-: | :- | :-: | :-: | :-: |
| 1 | [Program Design](./program-design) | Pending | Pending | |
| 2 | [Development Environments & Expressions](./development-environments-expressions) | Pending | Pending | |
| 3 | [Functions, Lists & Recursion](./functions-lists-recursion) | Pending | Pending | |
| 4 | [Tuples, Structs & Enums](./tuples-structs-enums) | Pending | Pending | |
| 5 | [Trees](./trees) | Pending | Pending | |
| 6 | [Generics & Higher-Order Functions](./generics-higher-order-functions) | Pending | Pending | |
| 7 | [Imperative Programming](./imperative-programming) | Pending | Pending | |
| 8 | [Queues](./queues) | Pending | Pending | |
| 9 | [Traits](./traits) | Pending | Pending | |
| 10 | [Hash Maps & Closures](./hash-maps-closures) | Pending | Pending | |
| 11 | [Case Study: Parser](./parser) | Pending | Pending | |
| 12 | [Case Study: Autodiff](./autodiff) | Pending | Pending | |
| 13 | [Case Study: Neural Network](./neural-network) | Pending | Pending | |
| 14 | [Case Study: Stack Machine](./stack-machine) | Pending | Pending | |
| Chapter | Topic | Slides | Video | Code Repository |
| :-----: | :------------------------------------------------------------------------------- | :-----: | :-----: | :-------------: |
| 1 | [Program Design](./program-design) | Pending | Pending | |
| 2 | [Development Environments & Expressions](./development-environments-expressions) | Pending | Pending | |
| 3 | [Functions, Lists & Recursion](./functions-lists-recursion) | Pending | Pending | |
| 4 | [Tuples, Structs & Enums](./tuples-structs-enums) | Pending | Pending | |
| 5 | [Trees](./trees) | Pending | Pending | |
| 6 | [Generics & Higher-Order Functions](./generics-higher-order-functions) | Pending | Pending | |
| 7 | [Imperative Programming](./imperative-programming) | Pending | Pending | |
| 8 | [Queues](./queues) | Pending | Pending | |
| 9 | [Traits](./traits) | Pending | Pending | |
| 10 | [Hash Maps & Closures](./hash-maps-closures) | Pending | Pending | |
| 11 | [Case Study: Parser](./parser) | Pending | Pending | |
| 12 | [Case Study: Autodiff](./autodiff) | Pending | Pending | |
| 13 | [Case Study: Neural Network](./neural-network) | Pending | Pending | |
| 14 | [Case Study: Stack Machine](./stack-machine) | Pending | Pending | |

Chapters 1 to 6 focus on functional programming, where we will learn about basic data structures and algorithms, and then delve into advanced topics such as higher-order functions and interfaces. Starting from Chapter 7, we will move on to imperative programming, where we will work with mutable data. Finally, we will conclude our study with an introduction to object-oriented programming. In the last few chapters, we will present some case studies to demonstrate how to use MoonBit to develop complex programs.

Expand All @@ -52,4 +52,4 @@ In this course, we will be using MoonBit as our programming language. The instal

## Acknowledgements

This course draws inspiration from [UPenn CIS 1200](https://www.seas.upenn.edu/~cis120/current/).
This course draws inspiration from [UPenn CIS 1200](https://www.seas.upenn.edu/~cis120/current/).
2 changes: 1 addition & 1 deletion docs/01-program-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ It is recommended to adopt a TDD workflow, namely,

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.

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$.)
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$.)
17 changes: 13 additions & 4 deletions docs/02-development-environments-expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ In the above program, a top-level function and a test block are defined. In the

Since this program does not generate any output, how exactly is it executed?

In order to write accurate programs, it is essential to understand how programs are executed. Therefore, it is necessary to establish a computational model that comprehends the process. MoonBit programs can be viewed using an expression-oriented programming approach. They are composed of expressions that represent values, and their execution involves reducing these expressions.
In order to write accurate programs, it is essential to understand how programs are executed. Therefore, it is necessary to establish a computational model that comprehends the process. MoonBit programs can be viewed using an expression-oriented programming approach. They are composed of expressions that represent values, and their execution involves reducing these expressions.

In contrast, imperative programming consists of statements that may modify the program's state. For example, statements may include "create a variable named `x`", "assign `5` to `x`", or "let `y` point to `x`", etc.

Expand Down Expand Up @@ -95,6 +95,7 @@ In static type systems, type checking is performed **before** the program is exe
MoonBit has a static type system, where its compiler performs type checking before runtime. This approach aims to minimize the likelihood of encountering runtime errors stemming from the execution of operations on incompatible data types, such as attempting arithmetic calculations on Boolean values. By conducting type checking in advance, MoonBit strives to prevent program interruptions and ensure accurate outcomes.

In MoonBit, each **identifier** can be associated with a unique type with a colon `:`. For example,

- `x: Int`
- `a: Double`
- `s: String`
Expand Down Expand Up @@ -122,6 +123,7 @@ While this chapter will not explore the underlying implementation of data, such
The first data type we will introduce here is the Boolean value, also known as a logical value. It is named after the mathematician George Boole, who is credited with inventing Boolean algebra.

In MoonBit, the type for Boolean values is `Bool`, and it can only have two possible values: `true` and `false`. The following are three basic operations it supports:

- NOT: true becomes false, false becomes true.
- Example: `not(true) == false`
- AND: both must be true to be true.
Expand All @@ -140,6 +142,7 @@ Quiz: How to define XOR (true if only one is true) using OR, AND, and NOT?
In mathematics, the set of integers is denoted as $\mathbb{Z}$ and is considered a countably infinite set. However, in computer science, integers in programming languages typically have a limited range due to hardware constraints.

In MoonBit, there are two integer types, each with a different range:

- Integer `Int`: ranging from $-2^{31}$ to $2^{31}-1$
- Long integer `Int64`: ranging from $-2^{63}$ to $2^{63}-1$

Expand Down Expand Up @@ -178,10 +181,12 @@ It is important to note that each character in MoonBit corresponds strictly to a
#### Tuples

Sometimes, it is necessary to represent data types that combine multiple pieces of information. For instance, a date can be represented by three numbers, and a person's personal information may include their name and age. In such cases, tuples can be used to combine data of different types with a fixed length. Tuples allow us to group together multiple values into a single entity.

- `(2023, 10, 24): (Int, Int, Int)`
- `("Bob", 3): (String, Int)`

We can access the data by using zero-based indexing.

- `(2023, 10, 24).0 == 2023`
- `(2023, 10, 24).1 == 10`

Expand Down Expand Up @@ -225,6 +230,7 @@ flowchart LR
```

We can denote the reduction of an $\texttt{<expression>}$ to a $\texttt{<value>}$ as $\texttt{<expression>} \Rightarrow \texttt{<value>}$. For example,

- $3 \Rightarrow 3$ (the reduction result of a value is itself)
- $3 + 4 \Rightarrow 7$
- $2 * (4 + 5) \Rightarrow 18$
Expand All @@ -245,6 +251,7 @@ Therefore, $(2 + 3) * (5 - 2) \Rightarrow 15$.
#### Variable Binding

In MoonBit, variable binding can be achieved using the syntax `let <identifier> : <type> = <expression>`. It assigns an identifier to a value that is represented by an expression. In many cases, the type declaration is optional as the compiler can infer it based on the type of the expression.

- `let x = 10`
- `let y = "String"`

Expand All @@ -255,7 +262,8 @@ By utilizing variable binding effectively, you can avoid complex nesting of expr
#### Expression Blocks and Scope

In MoonBit, expression blocks can be defined using the syntax
```

```text
{
Variable bindings
Variable bindings
Expand All @@ -279,6 +287,7 @@ It is important to note the direction of the arrows. On line 7, the `tmp` refers
#### Expression Reduction under Variable Binding

Expression reduction can be broken down into the following steps:

- Reduce the expression on the right-hand side of the variable binding.
- **Replace** occurrences of identifiers with their reduction results.
- Omit the variable binding part.
Expand Down Expand Up @@ -366,7 +375,7 @@ Conditional expressions enable you to obtain different values ​​based on spe

In MoonBit, its syntax is:

```
```text
if condition
expression block|if condition is true
else
Expand Down Expand Up @@ -411,4 +420,4 @@ In this chapter, we learned:
- Integers and floating-point numbers
- Characters and strings
- Tuples
- How to view MoonBit programs in terms of expressions and values, and understand the execution of MoonBit programs by reduction.
- How to view MoonBit programs in terms of expressions and values, and understand the execution of MoonBit programs by reduction.
Loading

0 comments on commit f1af1bd

Please sign in to comment.