model-0.5: Derive a model of a data type using Generics

Safe HaskellSafe





Error utilities

type Errors = [Error] Source #

A list of error messages

toErrors :: Bifunctor p => p a c -> p [a] c Source #

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"})

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.

Convertible a a Source #

Any type can be converted to itself.

Instance details

Defined in Data.Convertible.Tiny


safeConvert :: a -> ConvertResult a #

Convertible String QualName Source # 
Instance details

Defined in Data.Model.Types

Convertible QualName String Source # 
Instance details

Defined in Data.Model.Types

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.

Formatting utilities

dotted :: [String] -> String Source #

Intercalate a dot between the non empty elements of a list of strings.

>>> dotted []
>>> dotted ["","bc","de"]
>>> dotted ["bc","","de"]