From f01e9f3f847b6238ee5d9a6931564da3d3ef7218 Mon Sep 17 00:00:00 2001 From: Tom Kenny Date: Mon, 22 Jan 2024 20:25:38 +0800 Subject: 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" --- src/content/chapter3_data_types/lesson06_results/code.gleam | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') 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 { -- cgit v1.2.3