mmzk-typeid-0.6.0.1: A TypeID implementation for Haskell
LicenseMIT
Maintainermmzk1526@outlook.com
PortabilityGHC
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.KindID.Class

Description

This module contains the type-level mechanisms that are used to define custom KindID-ish identifier types.

Synopsis

Prefix

type ValidPrefix prefix = (KnownSymbol prefix, LengthSymbol prefix < 64, IsLowerSymbol prefix ~ 'True) Source #

A constraint for valid prefix Symbols.

class ToPrefix a Source #

A class that translates any kind to a Symbol. It is used to translate custom data kinds to a Symbol so that they can be used as KindID prefixes.

For example, suppose we have the following data structure that represents the prefixes we are going to use:

data Prefix = User | Post | Comment

Then we can make it an instance of ToPrefix like this:

instance ToPrefix 'User where
  type PrefixSymbol 'User = "user"

instance ToPrefix 'Post where
  type PrefixSymbol 'Post = "post"

instance ToPrefix 'Comment where
  type PrefixSymbol 'Comment = "comment"

Now we can use Prefix as a prefix for KindIDs, e.g.

do
  userID <- genKindID @'User -- Same as genKindID @"user"
  postID <- genKindID @'Post -- Same as genKindID @"post"
  commentID <- genKindID @'Comment -- Same as genKindID @"comment"

Associated Types

type PrefixSymbol a :: Symbol Source #

Instances

Instances details
ToPrefix (a :: Symbol) Source #

The PrefixSymbol of a Symbol is the Symbol itself.

Instance details

Defined in Data.KindID.Class

Associated Types

type PrefixSymbol a :: Symbol Source #

Helpers

type family LengthSymbol (prefix :: Symbol) :: Nat where ... Source #

The length of a Symbol as a Nat.

Equations

LengthSymbol prefix = LSUH (UnconsSymbol prefix) 

type family IsLowerSymbol (prefix :: Symbol) :: Bool where ... Source #

Is a Symbol lower case?

Equations

IsLowerSymbol prefix = ILSUH (UnconsSymbol prefix) 

type family IsLowerChar (ch :: Char) :: Bool where ... Source #

Is a type-level Char lower case?

Equations

IsLowerChar ch = (Compare '`' ch == 'LT) && (Compare ch '{' == 'LT) 

type family LSUH (uncons :: Maybe (Char, Symbol)) :: Nat where ... Source #

Length Symbol Uncons Helper.

Equations

LSUH 'Nothing = 0 
LSUH ('Just '(c, s)) = 1 + LengthSymbol s 

type family ILSUH (uncons :: Maybe (Char, Symbol)) :: Bool where ... Source #

Is Lower Symbol Uncons Helper.

Equations

ILSUH 'Nothing = 'True 
ILSUH ('Just '(c, s)) = IsLowerChar c && IsLowerSymbol s