mu-schema-0.2.0.0: Format-independent schemas for serialization
Safe HaskellSafe
LanguageHaskell2010

Mu.Schema.Annotations

Description

Libraries can define custom annotations to indicate additional information not found in the Schema itself. For example, Protocol Buffers requires a numerical identifier for each field in a record.

Synopsis

Annotate a schema

data Annotation domain typeName fieldName where Source #

Annotations proper.

Constructors

AnnSchema :: domain -> Annotation domain typeName fieldName

Annotation over the whole schema.

AnnType :: typeName -> domain -> Annotation domain typeName fieldName

Annotation over a type in the schema.

AnnField :: typeName -> fieldName -> domain -> Annotation domain typeName fieldName

Annotation over a field in a record or a choice in an enumeration.

type family AnnotatedSchema domain (sch :: Schema typeName fieldName) :: [Annotation domain typeName fieldName] Source #

This type family links each schema to its corresponding annotations from one domain.

type AnnotationDomain = Type Source #

Each annotation belongs to a domain.

Find annotations for an element

type family GetSchemaAnnotation (anns :: [Annotation domain t f]) :: domain where ... Source #

Find the annotation over the schema in the given set. If the annotation cannot be found, raise a TypeError.

Equations

GetSchemaAnnotation '[] = TypeError ('Text "cannot find schema annotation") 
GetSchemaAnnotation ('AnnSchema d ': rs) = d 
GetSchemaAnnotation (r ': rs) = GetSchemaAnnotation rs 

type family GetTypeAnnotation (anns :: [Annotation domain t f]) (ty :: t) :: domain where ... Source #

Find the annotation over the given type in the given set. If the annotation cannot be found, raise a TypeError.

Equations

GetTypeAnnotation '[] ty = TypeError ('Text "cannot find annotation for " :<>: 'ShowType ty) 
GetTypeAnnotation ('AnnType ty d ': rs) ty = d 
GetTypeAnnotation (r ': rs) ty = GetTypeAnnotation rs ty 

type family GetFieldAnnotation (anns :: [Annotation domain t f]) (ty :: t) (fl :: f) :: domain where ... Source #

Find the annotation over the given field or choice in the given type. If the annotation cannot be found, raise a TypeError.

Equations

GetFieldAnnotation '[] ty fl = TypeError ((('Text "cannot find annotation for " :<>: 'ShowType ty) :<>: 'Text "/") :<>: 'ShowType fl) 
GetFieldAnnotation ('AnnField ty fl d ': rs) ty fl = d 
GetFieldAnnotation (r ': rs) ty fl = GetFieldAnnotation rs ty fl