Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vscode
dist-newstyle
20 changes: 12 additions & 8 deletions Data/Convertible/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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. -}
Expand All @@ -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
Expand Down