Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module defines Term
s which comply with
a given Schema
. These Term
s are the main
form of values used internally by mu-haskell
.
In this module we make use of NP
and NS
as defined by sop-core.
These are the n-ary versions of a pair and
Either
, respectively. In other words, NP
puts together a bunch of values of different
types, NS
allows you to choose from a bunch
of types.
Synopsis
- data Term (sch :: Schema typeName fieldName) (t :: TypeDef typeName fieldName) where
- data Field (sch :: Schema typeName fieldName) (f :: FieldDef typeName fieldName) where
- Field :: FieldValue sch t -> Field sch (FieldDef name t)
- data FieldValue (sch :: Schema typeName fieldName) (t :: FieldType typeName) where
- FNull :: FieldValue sch TNull
- FPrimitive :: t -> FieldValue sch (TPrimitive t)
- FSchematic :: Term sch (sch :/: t) -> FieldValue sch (TSchematic t)
- FOption :: Maybe (FieldValue sch t) -> FieldValue sch (TOption t)
- FList :: [FieldValue sch t] -> FieldValue sch (TList t)
- FMap :: Ord (FieldValue sch k) => Map (FieldValue sch k) (FieldValue sch v) -> FieldValue sch (TMap k v)
- FUnion :: NS (FieldValue sch) choices -> FieldValue sch (TUnion choices)
- data NS (a :: k -> Type) (b :: [k]) :: forall k. (k -> Type) -> [k] -> Type where
- data NP (a :: k -> Type) (b :: [k]) :: forall k. (k -> Type) -> [k] -> Type where
- data Proxy (t :: k) :: forall k. k -> Type = Proxy
Interpretation
data Term (sch :: Schema typeName fieldName) (t :: TypeDef typeName fieldName) where Source #
Interpretation of a type in a schema.
TRecord :: NP (Field sch) args -> Term sch (DRecord name args) | A record given by the value of its fields. |
TEnum :: NS Proxy choices -> Term sch (DEnum name choices) | An enumeration given by one choice. |
TSimple :: FieldValue sch t -> Term sch (DSimple t) | A primitive value. |
Instances
(sch :/: sty) ~ (DEnum sty choices :: TypeDefB Type typeName fieldName) => FromSchema (sch :: Schema typeName fieldName) (sty :: typeName) (Term sch (DEnum sty choices :: TypeDefB Type typeName fieldName)) Source # | |
Defined in Mu.Schema.Class | |
(sch :/: sty) ~ DRecord sty fields => FromSchema (sch :: Schema typeName fieldName) (sty :: typeName) (Term sch (DRecord sty fields)) Source # | |
Defined in Mu.Schema.Class | |
(sch :/: sty) ~ (DEnum sty choices :: TypeDefB Type typeName fieldName) => ToSchema (sch :: Schema typeName fieldName) (sty :: typeName) (Term sch (DEnum sty choices :: TypeDefB Type typeName fieldName)) Source # | |
(sch :/: sty) ~ DRecord sty fields => ToSchema (sch :: Schema typeName fieldName) (sty :: typeName) (Term sch (DRecord sty fields)) Source # | |
Eq (FieldValue sch t) => Eq (Term sch (DSimple t :: TypeDefB Type typeName fieldName)) Source # | |
All (Compose Eq (Proxy :: ChoiceDef fieldName -> Type)) choices => Eq (Term sch (DEnum name choices :: TypeDefB Type typeName fieldName)) Source # | |
All (Compose Eq (Field sch)) args => Eq (Term sch (DRecord name args)) Source # | |
Show (FieldValue sch t) => Show (Term sch (DSimple t :: TypeDefB Type typeName fieldName)) Source # | |
(KnownName name, All (KnownName :: ChoiceDef fieldName -> Constraint) choices, All (Compose Show (Proxy :: ChoiceDef fieldName -> Type)) choices) => Show (Term sch (DEnum name choices :: TypeDefB Type typeName fieldName)) Source # | |
(KnownName name, All (Compose Show (Field sch)) args) => Show (Term sch (DRecord name args)) Source # | |
ToJSON (FieldValue sch t) => ToJSON (Term sch (DSimple t :: TypeDefB Type typeName fieldName)) Source # | |
ToJSONFields sch args => ToJSON (Term sch (DRecord name args)) Source # | |
ToJSONEnum choices => ToJSON (Term sch (DEnum name choices :: TypeDefB Type typeName fieldName)) Source # | |
FromJSON (FieldValue sch t) => FromJSON (Term sch (DSimple t :: TypeDefB Type typeName fieldName)) Source # | |
FromJSONFields sch args => FromJSON (Term sch (DRecord name args)) Source # | |
FromJSONEnum choices => FromJSON (Term sch (DEnum name choices :: TypeDefB Type typeName fieldName)) Source # | |
data Field (sch :: Schema typeName fieldName) (f :: FieldDef typeName fieldName) where Source #
Interpretation of a field.
Field :: FieldValue sch t -> Field sch (FieldDef name t) | A single field. Note that the contents are wrapped in a |
data FieldValue (sch :: Schema typeName fieldName) (t :: FieldType typeName) where Source #
Interpretation of a field type, by giving a value of that type.
FNull :: FieldValue sch TNull | Null value, as found in Avro and JSON. |
FPrimitive :: t -> FieldValue sch (TPrimitive t) | Value of a primitive type. |
FSchematic :: Term sch (sch :/: t) -> FieldValue sch (TSchematic t) | Term of another type in the schema. |
FOption :: Maybe (FieldValue sch t) -> FieldValue sch (TOption t) | Optional value. |
FList :: [FieldValue sch t] -> FieldValue sch (TList t) | List of values. |
FMap :: Ord (FieldValue sch k) => Map (FieldValue sch k) (FieldValue sch v) -> FieldValue sch (TMap k v) | Dictionary (key-value map) of values. |
FUnion :: NS (FieldValue sch) choices -> FieldValue sch (TUnion choices) | One single value of one of the specified types. |
Instances
data NS (a :: k -> Type) (b :: [k]) :: forall k. (k -> Type) -> [k] -> Type where #
An n-ary sum.
The sum is parameterized by a type constructor f
and
indexed by a type-level list xs
. The length of the list
determines the number of choices in the sum and if the
i
-th element of the list is of type x
, then the i
-th
choice of the sum is of type f x
.
The constructor names are chosen to resemble Peano-style
natural numbers, i.e., Z
is for "zero", and S
is for
"successor". Chaining S
and Z
chooses the corresponding
component of the sum.
Examples:
Z :: f x -> NS f (x ': xs) S . Z :: f y -> NS f (x ': y ': xs) S . S . Z :: f z -> NS f (x ': y ': z ': xs) ...
Note that empty sums (indexed by an empty list) have no non-bottom elements.
Two common instantiations of f
are the identity functor I
and the constant functor K
. For I
, the sum becomes a
direct generalization of the Either
type to arbitrarily many
choices. For
, the result is a homogeneous choice type,
where the contents of the type-level list are ignored, but its
length specifies the number of options.K
a
In the context of the SOP approach to generic programming, an n-ary sum describes the top-level structure of a datatype, which is a choice between all of its constructors.
Examples:
Z (I 'x') :: NS I '[ Char, Bool ] S (Z (I True)) :: NS I '[ Char, Bool ] S (Z (K 1)) :: NS (K Int) '[ Char, Bool ]
Z :: forall k (a :: k -> Type) (b :: [k]) (x :: k) (xs :: [k]). a x -> NS a (x ': xs) | |
S :: forall k (a :: k -> Type) (b :: [k]) (xs :: [k]) (x :: k). NS a xs -> NS a (x ': xs) |
Instances
HTrans (NS :: (k1 -> Type) -> [k1] -> Type) (NS :: (k2 -> Type) -> [k2] -> Type) | |
HAp (NS :: (k -> Type) -> [k] -> Type) | |
HCollapse (NS :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NS | |
HTraverse_ (NS :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NS hctraverse_ :: (AllN NS c xs, Applicative g) => proxy c -> (forall (a :: k0). c a => f a -> g ()) -> NS f xs -> g () # htraverse_ :: (SListIN NS xs, Applicative g) => (forall (a :: k0). f a -> g ()) -> NS f xs -> g () # | |
HSequence (NS :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NS hsequence' :: (SListIN NS xs, Applicative f) => NS (f :.: g) xs -> f (NS g xs) # hctraverse' :: (AllN NS c xs, Applicative g) => proxy c -> (forall (a :: k0). c a => f a -> g (f' a)) -> NS f xs -> g (NS f' xs) # htraverse' :: (SListIN NS xs, Applicative g) => (forall (a :: k0). f a -> g (f' a)) -> NS f xs -> g (NS f' xs) # | |
HIndex (NS :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NS | |
HApInjs (NS :: (k -> Type) -> [k] -> Type) | |
HExpand (NS :: (k -> Type) -> [k] -> Type) | |
All (Compose Eq f) xs => Eq (NS f xs) | |
(All (Compose Eq f) xs, All (Compose Ord f) xs) => Ord (NS f xs) | |
All (Compose Show f) xs => Show (NS f xs) | |
All (Compose NFData f) xs => NFData (NS f xs) | Since: sop-core-0.2.5.0 |
Defined in Data.SOP.NS | |
type Same (NS :: (k1 -> Type) -> [k1] -> Type) | |
type Prod (NS :: (k -> Type) -> [k] -> Type) | |
type CollapseTo (NS :: (k -> Type) -> [k] -> Type) a | |
Defined in Data.SOP.NS | |
type SListIN (NS :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NS | |
type AllN (NS :: (k -> Type) -> [k] -> Type) (c :: k -> Constraint) | |
Defined in Data.SOP.NS |
data NP (a :: k -> Type) (b :: [k]) :: forall k. (k -> Type) -> [k] -> Type where #
An n-ary product.
The product is parameterized by a type constructor f
and
indexed by a type-level list xs
. The length of the list
determines the number of elements in the product, and if the
i
-th element of the list is of type x
, then the i
-th
element of the product is of type f x
.
The constructor names are chosen to resemble the names of the list constructors.
Two common instantiations of f
are the identity functor I
and the constant functor K
. For I
, the product becomes a
heterogeneous list, where the type-level list describes the
types of its components. For
, the product becomes a
homogeneous list, where the contents of the type-level list are
ignored, but its length still specifies the number of elements.K
a
In the context of the SOP approach to generic programming, an n-ary product describes the structure of the arguments of a single data constructor.
Examples:
I 'x' :* I True :* Nil :: NP I '[ Char, Bool ] K 0 :* K 1 :* Nil :: NP (K Int) '[ Char, Bool ] Just 'x' :* Nothing :* Nil :: NP Maybe '[ Char, Bool ]
Nil :: forall k (a :: k -> Type) (b :: [k]). NP a ([] :: [k]) | |
(:*) :: forall k (a :: k -> Type) (b :: [k]) (x :: k) (xs :: [k]). a x -> NP a xs -> NP a (x ': xs) infixr 5 |
Instances
HTrans (NP :: (k1 -> Type) -> [k1] -> Type) (NP :: (k2 -> Type) -> [k2] -> Type) | |
HPure (NP :: (k -> Type) -> [k] -> Type) | |
HAp (NP :: (k -> Type) -> [k] -> Type) | |
HCollapse (NP :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NP | |
HTraverse_ (NP :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NP hctraverse_ :: (AllN NP c xs, Applicative g) => proxy c -> (forall (a :: k0). c a => f a -> g ()) -> NP f xs -> g () # htraverse_ :: (SListIN NP xs, Applicative g) => (forall (a :: k0). f a -> g ()) -> NP f xs -> g () # | |
HSequence (NP :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NP hsequence' :: (SListIN NP xs, Applicative f) => NP (f :.: g) xs -> f (NP g xs) # hctraverse' :: (AllN NP c xs, Applicative g) => proxy c -> (forall (a :: k0). c a => f a -> g (f' a)) -> NP f xs -> g (NP f' xs) # htraverse' :: (SListIN NP xs, Applicative g) => (forall (a :: k0). f a -> g (f' a)) -> NP f xs -> g (NP f' xs) # | |
All (Compose Eq f) xs => Eq (NP f xs) | |
(All (Compose Eq f) xs, All (Compose Ord f) xs) => Ord (NP f xs) | |
All (Compose Show f) xs => Show (NP f xs) | |
All (Compose Semigroup f) xs => Semigroup (NP f xs) | Since: sop-core-0.4.0.0 |
(All (Compose Monoid f) xs, All (Compose Semigroup f) xs) => Monoid (NP f xs) | Since: sop-core-0.4.0.0 |
All (Compose NFData f) xs => NFData (NP f xs) | Since: sop-core-0.2.5.0 |
Defined in Data.SOP.NP | |
type Same (NP :: (k1 -> Type) -> [k1] -> Type) | |
type Prod (NP :: (k -> Type) -> [k] -> Type) | |
type UnProd (NP :: (k -> Type) -> [k] -> Type) | |
type CollapseTo (NP :: (k -> Type) -> [k] -> Type) a | |
Defined in Data.SOP.NP | |
type SListIN (NP :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NP | |
type AllN (NP :: (k -> Type) -> [k] -> Type) (c :: k -> Constraint) | |
Defined in Data.SOP.NP | |
type AllZipN (NP :: (k -> Type) -> [k] -> Type) (c :: a -> b -> Constraint) | |
Defined in Data.SOP.NP |
data Proxy (t :: k) :: forall k. k -> Type #
Proxy
is a type that holds no data, but has a phantom parameter of
arbitrary type (or even kind). Its use is to provide type information, even
though there is no value available of that type (or it may be too costly to
create one).
Historically,
is a safer alternative to the
Proxy
:: Proxy
a'undefined :: a'
idiom.
>>>
Proxy :: Proxy (Void, Int -> Int)
Proxy
Proxy can even hold types of higher kinds,
>>>
Proxy :: Proxy Either
Proxy
>>>
Proxy :: Proxy Functor
Proxy
>>>
Proxy :: Proxy complicatedStructure
Proxy
Instances
Generic1 (Proxy :: k -> Type) | |
Monad (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Functor (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Applicative (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Foldable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Defined in Data.Foldable fold :: Monoid m => Proxy m -> m # foldMap :: Monoid m => (a -> m) -> Proxy a -> m # foldr :: (a -> b -> b) -> b -> Proxy a -> b # foldr' :: (a -> b -> b) -> b -> Proxy a -> b # foldl :: (b -> a -> b) -> b -> Proxy a -> b # foldl' :: (b -> a -> b) -> b -> Proxy a -> b # foldr1 :: (a -> a -> a) -> Proxy a -> a # foldl1 :: (a -> a -> a) -> Proxy a -> a # elem :: Eq a => a -> Proxy a -> Bool # maximum :: Ord a => Proxy a -> a # minimum :: Ord a => Proxy a -> a # | |
Traversable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
ToJSON1 (Proxy :: Type -> Type) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Proxy a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Proxy a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Proxy a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Proxy a] -> Encoding # | |
FromJSON1 (Proxy :: Type -> Type) | |
Alternative (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
MonadPlus (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Contravariant (Proxy :: Type -> Type) | |
Eq1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Ord1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Read1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Show1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Hashable1 (Proxy :: Type -> Type) | |
Defined in Data.Hashable.Class | |
Bounded (Proxy t) | Since: base-4.7.0.0 |
Enum (Proxy s) | Since: base-4.7.0.0 |
Eq (Proxy s) | Since: base-4.7.0.0 |
Ord (Proxy s) | Since: base-4.7.0.0 |
Read (Proxy t) | Since: base-4.7.0.0 |
Show (Proxy s) | Since: base-4.7.0.0 |
Ix (Proxy s) | Since: base-4.7.0.0 |
Generic (Proxy t) | |
Semigroup (Proxy s) | Since: base-4.9.0.0 |
Monoid (Proxy s) | Since: base-4.7.0.0 |
Hashable (Proxy a) | |
Defined in Data.Hashable.Class | |
ToJSON (Proxy a) | |
Defined in Data.Aeson.Types.ToJSON | |
FromJSON (Proxy a) | |
type Rep1 (Proxy :: k -> Type) | Since: base-4.6.0.0 |
type Rep (Proxy t) | Since: base-4.6.0.0 |