module Test.TypeSpec.Internal.Result
(
type Result
, type FAILED
, type OK
, type Try
, type DontTry
, type PrependToError
) where
import GHC.TypeLits
import Data.Kind
import Test.TypeSpec.Internal.Apply ()
import Test.TypeSpec.Internal.Either ()
type Result = Either ErrorMessage
type OK = 'Right
type FAILED = 'Left
type family
Try (e :: Result k) :: k where
Try (OK (d :: k)) = d
Try (FAILED m) = TypeError m
type family
DontTry (e :: Result r) :: Constraint where
DontTry (FAILED e) = ()
DontTry (OK okIsNotOk) =
TypeError ('Text "You specified this wasn't okay: "
':$$:
'Text " " ':<>: 'ShowType okIsNotOk
':$$:
'Text "... turns out it actually is!")
type family
PrependToError
(message :: ErrorMessage)
(result :: Result a)
:: Result a
where
PrependToError message (OK x) = OK x
PrependToError message (FAILED otherMessage) =
FAILED (message ':<>: otherMessage)