Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Synopsis
- type Errors = [Error]
- toErrors :: Bifunctor p => p a c -> p [a] c
- noErrors :: Errors -> Bool
- errsInContext :: (Convertible ctx String, Bifunctor p) => ctx -> p [String] c -> p [String] c
- inContext :: Convertible ctx String => ctx -> [String] -> [String]
- errorToConvertResult :: (Typeable b, Typeable a, Show a) => (a -> Either Error b) -> a -> ConvertResult b
- errorsToConvertResult :: (Typeable b, Typeable t, Show t) => (t -> Either Errors b) -> t -> ConvertResult b
- convertResultToError :: Bifunctor p => p ConvertError c -> p String c
- convertResultToErrors :: Bifunctor p => p ConvertError c -> p [String] c
- convertOrError :: Convertible a c => a -> Either String c
- class Convertible a b where
- safeConvert :: a -> ConvertResult b
- convert :: Convertible a b => a -> b
- type ConvertResult a = Either ConvertError a
- data ConvertError = ConvertError {}
- dotted :: [String] -> String
Dependencies
Error utilities
errsInContext :: (Convertible ctx String, Bifunctor p) => ctx -> p [String] c -> p [String] c Source #
Prefix errors with a contextual note
inContext :: Convertible ctx String => ctx -> [String] -> [String] Source #
Prefix a list of strings with a contextual note
>>>
inContext "0/0" ["Zero denominator"]
["In 0/0: Zero denominator"]
errorToConvertResult :: (Typeable b, Typeable a, Show a) => (a -> Either Error b) -> a -> ConvertResult b Source #
errorsToConvertResult :: (Typeable b, Typeable t, Show t) => (t -> Either Errors b) -> t -> ConvertResult b Source #
>>>
errorsToConvertResult (const (Left ["Bad format","Invalid value"])) ".." :: ConvertResult Int
Left (ConvertError {convSourceValue = "\"..\"", convSourceType = "[Char]", convDestType = "Int", convErrorMessage = "Bad format, Invalid value"})
convertResultToError :: Bifunctor p => p ConvertError c -> p String c Source #
convertResultToErrors :: Bifunctor p => p ConvertError c -> p [String] c Source #
convertOrError :: Convertible a c => a -> Either String c Source #
>>>
import Data.Word
>>>
convertOrError 'a' :: Either Error Word
Right 97
>>>
convertOrError (1E50::Double) :: Either Error Word64
Left "Convertible: error converting source data 1.0e50 of type Double to type Word64: Input value outside of bounds: (0,18446744073709551615)"
Convertible re-exports
class Convertible a b where #
A typeclass that represents something that can be converted.
A Convertible a b
instance represents an a
that can be converted to a b
.
safeConvert :: a -> ConvertResult b #
Convert a
to b
, returning Right on success and Left on error.
For a simpler interface, see convert
.
Instances
Convertible a a Source # | Any type can be converted to itself. |
Defined in Data.Convertible.Tiny safeConvert :: a -> ConvertResult a # | |
Convertible String QualName Source # | |
Defined in Data.Model.Types safeConvert :: String -> ConvertResult QualName # | |
Convertible QualName String Source # | |
Defined in Data.Model.Types safeConvert :: QualName -> ConvertResult String # |
convert :: Convertible a b => a -> b #
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
.
type ConvertResult a = Either ConvertError a #
The result of a safe conversion via safeConvert
.
data ConvertError #
How we indicate that there was an error.
Instances
Eq ConvertError | |
Defined in Data.Convertible.Base (==) :: ConvertError -> ConvertError -> Bool # (/=) :: ConvertError -> ConvertError -> Bool # | |
Read ConvertError | |
Defined in Data.Convertible.Base readsPrec :: Int -> ReadS ConvertError # readList :: ReadS [ConvertError] # | |
Show ConvertError | |
Defined in Data.Convertible.Base showsPrec :: Int -> ConvertError -> ShowS # show :: ConvertError -> String # showList :: [ConvertError] -> ShowS # | |
Error ConvertError | |
Defined in Data.Convertible.Base noMsg :: ConvertError # strMsg :: String -> ConvertError # |