Skip to content

Commit

Permalink
(Debug, Show) -> Show
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfettes committed Jul 23, 2024
1 parent 056037f commit c7d981f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions docs/11-parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ In MoonBit, we define tokens as enums, and tokens can be values containing integ
```moonbit
enum Token {
Value(Int); LParen; RParen; Plus; Minus; Multiply; Divide
} derive(Debug, Show)
} derive(Show)
```

### Parser Combinator
Expand Down Expand Up @@ -321,8 +321,8 @@ fn parse_string[E : Expr](str: String) -> Option[(E, String, @immut/list.List[To
Thus, we only need to define different implementations and specify which one to use in MoonBit. The former involves defining different methods for the data structure to meet the requirements of the interface, such as the `number` method in lines 4 and 5. The latter specifies the return type of functions to indicate the specific type parameter, as shown in lines 8 and 10. In line 8, we will obtain the expression tree constructed from enums, while in line 10 we can directly obtain the result. You can also add other interpretations, like converting an expression into a formatted string by removing extra parentheses and whitespaces.

```moonbit no-check
enum Expression { ... } derive(Debug) // Implementation of syntax tree
type BoxedInt Int derive(Debug) // Implementation of integer
enum Expression { ... } derive(Show) // Implementation of syntax tree
type BoxedInt Int derive(Show) // Implementation of integer
// Other interface implementation methods omitted
fn BoxedInt::number(i: Int) -> BoxedInt { BoxedInt(i) }
fn Expression::number(i: Int) -> Expression { Number(i) }
Expand Down
6 changes: 3 additions & 3 deletions docs/12-autodiff.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ enum Symbol {
Var(Int)
Add(Symbol, Symbol)
Mul(Symbol, Symbol)
} derive(Debug, Show)
} derive(Show)
// Define simple constructors and overload operators
fn Symbol::constant(d : Double) -> Symbol { Constant(d) }
Expand Down Expand Up @@ -186,7 +186,7 @@ We will start with forward differentiation. It is relatively straightforward tha
struct Forward {
value : Double // Current node value f
derivative : Double // Current node derivative f'
} derive(Debug, Show)
} derive(Show)
fn Forward::constant(d : Double) -> Forward { { value: d, derivative: 0.0 } }
fn Forward::value(f : Forward) -> Double { f.value }
Expand Down Expand Up @@ -243,7 +243,7 @@ Here we demonstrate an implementation in MoonBit. The backward differentiation n
struct Backward {
value : Double // Current node value
backward : (Double) -> Unit // Update the partial derivative of the current path
} derive(Debug, Show)
} derive(Show)
fn Backward::var(value : Double, diff : Ref[Double]) -> Backward {
// Update the partial derivative along a computation path df / dvi * dvi / dx
Expand Down

0 comments on commit c7d981f

Please sign in to comment.