type-spec-0.4.0.0: Type Level Specification by Example
Safe HaskellNone
LanguageHaskell2010

Test.TypeSpec.Internal.Result

Description

A result type used in constraints inside TypeSpec to chain computations that may fail with a TypeError.

Synopsis

Results that with TypeErrors

type Result = Either ErrorMessage Source #

When a type level expectation is tested, it might be that compound expectations fail. In order to have a small, precise error message, the type level assertion results are made to have kind Result.

type FAILED = 'Left :: a -> Either a b Source #

A nice alias for Right

type OK = 'Right :: b -> Either a b Source #

A nice alias for Left

type family Try (e :: Result k) :: k where ... Source #

Return the result or fail with a TypeError

Equations

Try (OK d :: Either ErrorMessage k) = d 
Try (FAILED m :: Either ErrorMessage k) = TypeError m :: k 

type family DontTry (e :: Result r) where ... Source #

A constraint that is satisfied if the parameter is Left. Fails with a TypeError otherwise.

Equations

DontTry (FAILED e :: Either ErrorMessage r) = () 
DontTry (OK okIsNotOk :: Either ErrorMessage t) = TypeError (('Text "You specified this wasn't okay: " ':$$: ('Text " " ':<>: 'ShowType okIsNotOk)) ':$$: 'Text "... turns out it actually is!") :: Constraint 

Extending Error Messages

type family PrependToError (message :: ErrorMessage) (result :: Result a) :: Result a where ... Source #

In case of Left ErrorMessage prepend a message to the message, if the parameter was Right x just return Right x.

Equations

PrependToError message (OK x :: Either ErrorMessage b) = OK x 
PrependToError message (FAILED otherMessage :: Either ErrorMessage a) = FAILED (message ':<>: otherMessage)