Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
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
- data Annotation domain typeName fieldName where
- AnnSchema :: domain -> Annotation domain typeName fieldName
- AnnType :: typeName -> domain -> Annotation domain typeName fieldName
- AnnField :: typeName -> fieldName -> domain -> Annotation domain typeName fieldName
- type family AnnotatedSchema domain (sch :: Schema typeName fieldName) :: [Annotation domain typeName fieldName]
- type AnnotationDomain = Type
- type family GetSchemaAnnotation (anns :: [Annotation domain t f]) :: domain where ...
- type family GetTypeAnnotation (anns :: [Annotation domain t f]) (ty :: t) :: domain where ...
- type family GetFieldAnnotation (anns :: [Annotation domain t f]) (ty :: t) (fl :: f) :: domain where ...
Annotate a schema
data Annotation domain typeName fieldName where Source #
Annotations proper.
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
.
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
.
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
.
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 |