Copyright | © Jonathan Lorimer 2023 |
---|---|
License | MIT |
Maintainer | jonathanlorimer@pm.me |
Stability | stable |
Safe Haskell | None |
Language | Haskell2010 |
This module provides type level assertions so that we can constrain the instances user's can create, and give them good error messages
Since: 0.0.2.0
Synopsis
- class Assert (pred :: Bool) (msg :: ErrorMessage)
- type family IsTopLevelRecord (f :: k -> Type) :: Bool where ...
- type AssertTopLevelRecord (constraint :: Type -> Constraint) a = Assert (IsTopLevelRecord (Rep a)) (((('Text "\128683 Cannot derive " ':<>: 'ShowType constraint) ':<>: 'Text " instance for ") ':<>: 'ShowType a) ':$$: (('Text "\128161 " ':<>: 'ShowType constraint) ':<>: 'Text " must be derived on a top level record type with named fields."))
Documentation
class Assert (pred :: Bool) (msg :: ErrorMessage) Source #
A type level helper for creating custom error messages based on a predicate
Since: 0.0.2.0
type family IsTopLevelRecord (f :: k -> Type) :: Bool where ... Source #
A type level predicate that helps us identify top level product types
Since: 0.0.2.0
IsTopLevelRecord (V1 :: k -> Type) = 'False | |
IsTopLevelRecord (U1 :: k -> Type) = 'False | |
IsTopLevelRecord (K1 i c :: k -> Type) = 'False | |
IsTopLevelRecord (M1 D c f :: k -> Type) = IsTopLevelRecord f | |
IsTopLevelRecord (M1 C c f :: k -> Type) = IsTopLevelRecord f | |
IsTopLevelRecord (M1 S c f :: k -> Type) = 'True | |
IsTopLevelRecord (f :*: g :: k -> Type) = IsTopLevelRecord f | |
IsTopLevelRecord (f :+: g :: k -> Type) = 'False |
type AssertTopLevelRecord (constraint :: Type -> Constraint) a = Assert (IsTopLevelRecord (Rep a)) (((('Text "\128683 Cannot derive " ':<>: 'ShowType constraint) ':<>: 'Text " instance for ") ':<>: 'ShowType a) ':$$: (('Text "\128161 " ':<>: 'ShowType constraint) ':<>: 'Text " must be derived on a top level record type with named fields.")) Source #
A custom error message for non-top-level records
Since: 0.0.2.0