From c7d981f09ad491ec6d8e039b36a65bd094a4cdd3 Mon Sep 17 00:00:00 2001 From: Haoxiang Fei Date: Tue, 23 Jul 2024 15:51:43 +0800 Subject: [PATCH] (Debug, Show) -> Show --- docs/11-parser.md | 6 +++--- docs/12-autodiff.md | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/11-parser.md b/docs/11-parser.md index 3b043a3..0b9834a 100644 --- a/docs/11-parser.md +++ b/docs/11-parser.md @@ -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 @@ -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) } diff --git a/docs/12-autodiff.md b/docs/12-autodiff.md index 275628e..63e2750 100644 --- a/docs/12-autodiff.md +++ b/docs/12-autodiff.md @@ -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) } @@ -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 } @@ -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