From bf8dc2833eafe9215a90c10837223ae5a707496d Mon Sep 17 00:00:00 2001 From: Alice Rixte Date: Tue, 8 Jul 2025 11:08:36 +0200 Subject: [PATCH 1/2] Add .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b3185e1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vscode +dist-newstyle \ No newline at end of file From a4e39b898be05aca61d8722b52c838c4a761d09e Mon Sep 17 00:00:00 2001 From: Alice Rixte Date: Tue, 8 Jul 2025 11:11:09 +0200 Subject: [PATCH 2/2] Move convert inside Convertible. Fixes #19. --- Data/Convertible/Base.hs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Data/Convertible/Base.hs b/Data/Convertible/Base.hs index f202d34..ed25caa 100644 --- a/Data/Convertible/Base.hs +++ b/Data/Convertible/Base.hs @@ -47,6 +47,17 @@ class Convertible a b where {- | Convert @a@ to @b@, returning Right on success and Left on error. For a simpler interface, see 'convert'. -} safeConvert :: a -> ConvertResult b + safeConvert = Right . convert + {-# INLINE safeConvert #-} + + {- | Convert from one type of data to another. Raises an exception if there + is an error with the conversion. For a function that does not raise an + exception in that case, see 'safeConvert'. -} + convert :: a -> b + convert x = + case safeConvert x of + Left e -> error (prettyConvertError e) + Right r -> r {- {- | Any type can be converted to itself. -} @@ -60,14 +71,7 @@ instance Convertible a b => Convertible [a] [b] where safeConvert = mapM safeConvert -} -{- | Convert from one type of data to another. Raises an exception if there is -an error with the conversion. For a function that does not raise an exception -in that case, see 'safeConvert'. -} -convert :: Convertible a b => a -> b -convert x = - case safeConvert x of - Left e -> error (prettyConvertError e) - Right r -> r + {- instance Convertible Int Double where