Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
- class Valid a where
- data ValidationResult
- ensure :: Bool -> String -> ValidationResult
- withContext :: String -> ValidationResult -> ValidationResult
- errorMessages :: ValidationResult -> Maybe String
- validateNamed :: Valid a => (name -> String) -> [(name, a)] -> ValidationResult
- ensureValid :: ValidationResult -> IO ()
Documentation
Type class for types that admit "malformed" values, and must thus be checked.
Although implementing the isValid
method is sufficient, it will result in poor
error messages. Therefore, implementing the validate
method is recommended.
Checks if the given value is well-formed
validate :: a -> ValidationResult Source #
Checks if the given value is well-formed, providing an explanation of any errors encountered.
ensure :: Bool -> String -> ValidationResult Source #
Return IsValid
if the given boolean is true, otherwise return IsInvalid
with the given error message.
withContext :: String -> ValidationResult -> ValidationResult Source #
Prepends the indication of context to any error messages produced by the validation result.
errorMessages :: ValidationResult -> Maybe String Source #
Obtains the error messages produced by validation, or Nothing
if no error was found
validateNamed :: Valid a => (name -> String) -> [(name, a)] -> ValidationResult Source #
Validates a list of named values, modifying their names with the given function.
ensureValid :: ValidationResult -> IO () Source #
If the given validation detected some error, prints the error out and exits with failure.