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

Data.KindID.Class

Contents

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 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 | SuperUser

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"

instance ToPrefix 'SuperUser where
  type PrefixSymbol 'SuperUser = "super_user"

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"
  suID      <- genKindID @'SuperUser -- Same as genKindID @"super_user"

Associated Types

type PrefixSymbol a :: Symbol Source #

The associated type family that converts a into a Symbol.

Instances

Instances details
ToPrefix (s :: Symbol) Source #

The PrefixSymbol of a Symbol is the Symbol itself.

Instance details

Defined in Data.KindID.Class

Associated Types

type PrefixSymbol s :: Symbol Source #