Data.Error
No module comment.
What every payload in the shared error channel can do.
Typed is a superclass so that a packed payload can be asked what it is:
the Error dictionary an existential carries has the Typed one inside
it, which is how cast reaches a rep it never saw packed.
The shared recoverable-error channel. A source packs
its own concrete payload once, with fail; every caller in between
propagates the result with ? and never converts anything. What makes that
possible is the constructor's [Error e] bracket: the payload's type is
hidden, and its Error dictionary travels with the value, so a caller that
knows nothing about the source can still ask for its message.
cause is how context is added without losing an origin. context builds a
new error around the one it is given rather than repacking it, so the inner
payload and everything below it stay reachable through causeOf. GHC's
annotations went the other way -- a rethrow cleared the context and silently
dropped it (Well-Typed, 2026) -- and a field that is only ever written by
context cannot lose anything that way.
Enter the channel. Left(fail(ParseError { .. })) is the shape at a source.
Move a whole result into the shared channel: mapLeft through fail.
It lives here rather than on Either because Either knows nothing about
errors, and it is written in terms of fail rather than packing directly so
that entering the channel has exactly one implementation -- whatever fail
comes to do about already-packed payloads and captured call sites, promotion
does too, without a second place to keep in step.
Add context, keeping inner as the cause. The new payload is what a reader
sees first; the original is one causeOf away and still carries its own.
The whole chain, outermost first.
Recover the concrete payload, if it is the type asked for.
This is the whole reason Typed is a superclass of Error: opening the
error gives a payload whose type nothing here knows, and the dictionary
packed beside it answers what that type was. Comparing that rep with the
caller's is the check -- there is nothing downstream that would catch a
wrong answer, which is why a program may not write a Typed instance.
The conversion runs only once the type reps compare equal: Prim.castAs is
total and unchecked, and is spellable only from a library module, so no
unchecked coercion reaches ordinary Turkey.
One of two errors, as a layer that wraps another describes its failures:
its own on the Left, the one it wraps on the Right. The message is the
side's own, with nothing added, so a layer's error reads as what went wrong.