Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Helper utilities for rendering mismatch-type errors.
For cases where it's useful to get a diff-style mismatch report, i.e. where types can be rendered multi-line, a few override instances are needed.
The diff is produced by printing the types in a multiline format, then computing
the line diff with the standard algorithm (as implemented by the Diff
package).
In general, assuming the type in question is T
, those instances
can look like this:
instance Buildable (MismatchError T) where build = buildRenderDocExtended instance RenderDoc (MismatchError T) where renderDoc ctx = renderDocDiff ctx . fmap Prettier
The fmap Prettier
part is only required to enable multi-line rendering.
Additionally, if there's a need to show mismatch errors for lists, the following instance can be used:
instance RenderDoc (MismatchError [T]) where renderDoc ctx = renderDocDiffList ctx . (fmap . fmap) Prettier
Synopsis
- data MismatchError a = MkMismatchError {
- meExpected :: a
- meActual :: a
- renderDocDiff :: RenderDoc a => RenderContext -> MismatchError a -> Doc
- renderDocDiffList :: RenderDoc a => RenderContext -> MismatchError [a] -> Doc
Documentation
data MismatchError a Source #
A helper record datatype representing a mismatch between two values of some type. One is assumed to be in some sense the "expected" value, the other one is assumed to be the "actual" value.
MkMismatchError | |
|
Instances
renderDocDiff :: RenderDoc a => RenderContext -> MismatchError a -> Doc Source #
renderDocDiffList :: RenderDoc a => RenderContext -> MismatchError [a] -> Doc Source #