diff options
author | Tom Kenny <tom@twome.name> | 2024-01-22 20:25:38 +0800 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2024-02-06 16:51:57 +0000 |
commit | f01e9f3f847b6238ee5d9a6931564da3d3ef7218 (patch) | |
tree | 2c0ccc3665b02e62d6f9d62439f3170fc398e129 /src/content | |
parent | a44fae606fe361d4c9058fc5b3383a1e742d4325 (diff) | |
download | tour-f01e9f3f847b6238ee5d9a6931564da3d3ef7218.tar.gz tour-f01e9f3f847b6238ee5d9a6931564da3d3ef7218.zip |
Distinguish Result's `Error` from custom error type
Give the custom type for errors a different name from the Result data constructor "Error", to avoid confusion between the type-level and data-level meanings of the identifier "Error"
Diffstat (limited to 'src/content')
-rw-r--r-- | src/content/chapter3_data_types/lesson06_results/code.gleam | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/content/chapter3_data_types/lesson06_results/code.gleam b/src/content/chapter3_data_types/lesson06_results/code.gleam index ba7d5d8..ae00bba 100644 --- a/src/content/chapter3_data_types/lesson06_results/code.gleam +++ b/src/content/chapter3_data_types/lesson06_results/code.gleam @@ -8,12 +8,12 @@ pub fn main() { io.debug(buy_pastry(3)) } -pub type Error { +pub type PurchaseError { NotEnoughMoney(required: Int) NotLuckyEnough } -fn buy_pastry(money: Int) -> Result(Int, Error) { +fn buy_pastry(money: Int) -> Result(Int, PurchaseError) { case money >= 5 { True -> case int.random(4) == 0 { |