cfg-0.0.2.2: Type directed application configuration parsing and accessors
Copyright© Jonathan Lorimer 2023
LicenseMIT
Maintainerjonathanlorimer@pm.me
Stabilitystable
Safe HaskellNone
LanguageHaskell2010

Cfg.Deriving.Assert

Description

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

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

Instances

Instances details
(TypeError msg :: ()) ~ '() => Assert 'False msg Source # 
Instance details

Defined in Cfg.Deriving.Assert

Assert 'True msg Source # 
Instance details

Defined in Cfg.Deriving.Assert

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

Equations

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