diff --git a/moonbit-tour/tour/chapter2_data_types/lesson4_newtype/index.mbt b/moonbit-tour/tour/chapter2_data_types/lesson4_newtype/index.mbt index 3fc4a2de..717137ad 100644 --- a/moonbit-tour/tour/chapter2_data_types/lesson4_newtype/index.mbt +++ b/moonbit-tour/tour/chapter2_data_types/lesson4_newtype/index.mbt @@ -4,8 +4,9 @@ type UserName String fn main { let user_id : UserId = UserId(1) let user_name : UserName = UserName("Alice") - let UserId(id) = user_id - let UserName(name) = user_name println(user_id._) println(user_name._) + // use some pattern matching to extract the values + let UserId(id) = user_id + let UserName(name) = user_name } diff --git a/moonbit-tour/tour/chapter2_data_types/lesson4_newtype/index.md b/moonbit-tour/tour/chapter2_data_types/lesson4_newtype/index.md index e69de29b..7143fd9c 100644 --- a/moonbit-tour/tour/chapter2_data_types/lesson4_newtype/index.md +++ b/moonbit-tour/tour/chapter2_data_types/lesson4_newtype/index.md @@ -0,0 +1,6 @@ +# Newtype + +Newtypes are similar to enums with only one constructor (with the same name as the newtype itself). You can use the constructor to create values of the newtype and use `._` to extract the internal representation. + +*Pattern matching* can also be used. + diff --git a/moonbit-tour/tour/chapter2_data_types/lesson4_option/index.mbt b/moonbit-tour/tour/chapter2_data_types/lesson5_option/index.mbt similarity index 100% rename from moonbit-tour/tour/chapter2_data_types/lesson4_option/index.mbt rename to moonbit-tour/tour/chapter2_data_types/lesson5_option/index.mbt diff --git a/moonbit-tour/tour/chapter2_data_types/lesson4_option/index.md b/moonbit-tour/tour/chapter2_data_types/lesson5_option/index.md similarity index 100% rename from moonbit-tour/tour/chapter2_data_types/lesson4_option/index.md rename to moonbit-tour/tour/chapter2_data_types/lesson5_option/index.md diff --git a/moonbit-tour/tour/chapter2_data_types/lesson5_result/index.mbt b/moonbit-tour/tour/chapter2_data_types/lesson6_result/index.mbt similarity index 100% rename from moonbit-tour/tour/chapter2_data_types/lesson5_result/index.mbt rename to moonbit-tour/tour/chapter2_data_types/lesson6_result/index.mbt diff --git a/moonbit-tour/tour/chapter2_data_types/lesson5_result/index.md b/moonbit-tour/tour/chapter2_data_types/lesson6_result/index.md similarity index 100% rename from moonbit-tour/tour/chapter2_data_types/lesson5_result/index.md rename to moonbit-tour/tour/chapter2_data_types/lesson6_result/index.md