Safe Haskell | None |
---|---|
Language | GHC2021 |
Codec.CBOR.Cuddle.Huddle.HuddleM
Description
Monad for declaring Huddle constructs
Synopsis
- text :: Text -> Literal
- (==>) :: (IsType0 a, IsEntryLike me) => Key -> a -> me
- sized :: forall c a s. (IsSizeable a, IsSize s, IsConstrainable c a) => c -> s -> Constrained
- data Value a where
- int :: Integer -> Literal
- arr :: ArrayChoice -> ArrayChoice
- (/) :: (IsChoosable a c, IsChoosable b c) => a -> b -> Choice c
- a :: (IsType0 a, IsGroupOrArrayEntry e) => a -> e
- (...) :: (IsRangeBound a, IsRangeBound b) => a -> b -> Ranged
- le :: (IsComparable a, IsConstrainable c a) => c -> Word64 -> Constrained
- data Group
- type Rule = Named Type0
- data Huddle
- data HuddleItem
- huddleAugment :: Huddle -> Huddle -> Huddle
- data Named a
- class IsType0 a where
- toType0 :: a -> Type0
- comment :: HasField' "description" a (Maybe Text) => Text -> a -> a
- mp :: MapChoice -> MapChoice
- asKey :: IsType0 r => r -> Key
- idx :: Word64 -> Key
- grp :: Group -> Group
- class CanQuantify a where
- opt :: CanQuantify a => a -> a
- seal :: a -> Seal a
- sarr :: ArrayChoice -> Seal Array
- smp :: MapChoice -> Seal Map
- data Literal
- bstr :: ByteString -> Literal
- class IsConstrainable a x | a -> x
- class IsSizeable (a :: k)
- cbor :: (IsCborable b, IsConstrainable c b) => c -> Rule -> Constrained
- tag :: Word64 -> a -> Tagged a
- data GRef
- type GRuleDef = Named (GRule GRef)
- type GRuleCall = Named (GRule Type2)
- binding2 :: (IsType0 t0, IsType0 t1) => (GRef -> GRef -> Rule) -> t0 -> t1 -> GRuleCall
- callToDef :: GRule Type2 -> GRule GRef
- collectFrom :: [HuddleItem] -> Huddle
- collectFromInit :: [HuddleItem] -> Huddle
- toCDDL :: Huddle -> CDDL
- toCDDLNoRoot :: Huddle -> CDDL
- (=:=) :: IsType0 a => Text -> a -> HuddleM Rule
- (=:~) :: Text -> Group -> HuddleM (Named Group)
- (=::=) :: IsType0 a => Text -> a -> Rule
- binding :: IsType0 t0 => (GRef -> Rule) -> HuddleM (t0 -> GRuleCall)
- setRootRules :: [Rule] -> HuddleM ()
- huddleDef :: HuddleM a -> Huddle
- huddleDef' :: HuddleM a -> (a, Huddle)
- include :: Includable a => a -> HuddleM a
- unsafeIncludeFromHuddle :: Huddle -> Text -> HuddleM HuddleItem
Documentation
sized :: forall c a s. (IsSizeable a, IsSize s, IsConstrainable c a) => c -> s -> Constrained Source #
Declare a size constraint on an int-style type or reference. Since 0.3.4 this has worked for reference types as well as values.
Type-parametrised value type handling CBOR primitives. This is used to constrain the set of constraints which can apply to a given postlude type.
Constructors
VBool :: Value Bool | |
VUInt :: Value Int | |
VNInt :: Value Int | |
VInt :: Value Int | |
VHalf :: Value Float | |
VFloat :: Value Float | |
VDouble :: Value Double | |
VBytes :: Value ByteString | |
VText :: Value Text | |
VAny :: Value Void | |
VNil :: Value Void |
Instances
Show (Value a) Source # | |
IsType0 (Value a) Source # | |
Defined in Codec.CBOR.Cuddle.Huddle | |
IsConstrainable (Value a) a Source # | |
Defined in Codec.CBOR.Cuddle.Huddle Methods toConstrainable :: Value a -> Constrainable a |
arr :: ArrayChoice -> ArrayChoice Source #
This function is used solely to resolve type inference by explicitly identifying something as an array.
(/) :: (IsChoosable a c, IsChoosable b c) => a -> b -> Choice c infixl 9 Source #
Allow choices between constructions
in CDDL, /
a choice between types (concretely, between Type1 values, to
make a Type0). //
allows choice between groups. We can illustrate the
difference with the following snippet:
foo = [ 0 1, uint 2 3, tstr ]
This construction would match either of the following:
[0, 3] [2, "Hello World"]
In other words, the //
binds less strongly than comma (',') in CDDL.
In Haskell, of course, we cannot have syntax inside an array which binds
stronger than the comma. so we have to do things a little differently. The
way this is handled at the moment is that /
has special treatment for
arrays/groups, where it will, instead of creating a type-level choice, merge
the two arraysgroupsmaps into a single one containing a group choice.
If one instead wants the behaviour corresponding to the CDDL /
for arrays,
maps or groups, one can "seal" the array or group using the seal
, sarr
or
smp
functions. For example:
"foo" =:= sarr [0, a VUInt] / sarr [1, a VText]
Generates a choice (at the Type0
) level between two arrays, whereas
"foo" =:= arr [0, a VUInt] / arr [1, a VUInt]
will generate a single array containing a group choice between two groups.
As such, there is no //
operator in Huddle.
a :: (IsType0 a, IsGroupOrArrayEntry e) => a -> e Source #
Explicitly cast an item in an Array as an ArrayEntry.
(...) :: (IsRangeBound a, IsRangeBound b) => a -> b -> Ranged infixl 9 Source #
Establish a closed range bound.
le :: (IsComparable a, IsConstrainable c a) => c -> Word64 -> Constrained Source #
Top-level Huddle type is a list of rules.
Instances
Semigroup Huddle Source # | This semigroup instance: - Takes takes the roots from the RHS unless they are empty, in which case it takes the roots from the LHS - Uses the RHS to override items on the LHS where they share a name. The value from the RHS is taken, but the index from the LHS is used. Note that this allows replacing items in the middle of a tree without updating higher-level items which make use of them - that is, we do not need to "close over" higher-level terms, since by the time they have been built into a huddle structure, the references have been converted to keys. | ||||
Generic Huddle Source # | |||||
Defined in Codec.CBOR.Cuddle.Huddle Associated Types
| |||||
IsList Huddle Source # | This instance is mostly used for testing | ||||
Show Huddle Source # | |||||
Default Huddle Source # | |||||
Defined in Codec.CBOR.Cuddle.Huddle | |||||
type Rep Huddle Source # | |||||
Defined in Codec.CBOR.Cuddle.Huddle type Rep Huddle = D1 ('MetaData "Huddle" "Codec.CBOR.Cuddle.Huddle" "cuddle-0.5.0.0-H0bbRBZdSvH43WSgb38tp7" 'False) (C1 ('MetaCons "Huddle" 'PrefixI 'True) (S1 ('MetaSel ('Just "roots") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Rule]) :*: S1 ('MetaSel ('Just "items") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (OMap Text HuddleItem)))) | |||||
type Item Huddle Source # | |||||
Defined in Codec.CBOR.Cuddle.Huddle |
data HuddleItem Source #
Instances
Instances
Functor Named Source # | |||||
IsType0 GRuleCall Source # | |||||
Defined in Codec.CBOR.Cuddle.Huddle | |||||
IsType0 Rule Source # | |||||
Defined in Codec.CBOR.Cuddle.Huddle | |||||
Generic (Named a) Source # | |||||
Defined in Codec.CBOR.Cuddle.Huddle Associated Types
| |||||
Show (Named a) Source # | |||||
IsType0 (Named Group) Source # | |||||
type Rep (Named a) Source # | |||||
Defined in Codec.CBOR.Cuddle.Huddle type Rep (Named a) = D1 ('MetaData "Named" "Codec.CBOR.Cuddle.Huddle" "cuddle-0.5.0.0-H0bbRBZdSvH43WSgb38tp7" 'False) (C1 ('MetaCons "Named" 'PrefixI 'True) (S1 ('MetaSel ('Just "name") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: (S1 ('MetaSel ('Just "value") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Just "description") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text))))) |
class IsType0 a where Source #
Instances
IsType0 ByteString Source # | |
Defined in Codec.CBOR.Cuddle.Huddle Methods toType0 :: ByteString -> Type0 Source # | |
IsType0 GRef Source # | |
Defined in Codec.CBOR.Cuddle.Huddle | |
IsType0 GRuleCall Source # | |
Defined in Codec.CBOR.Cuddle.Huddle | |
IsType0 HuddleItem Source # | |
Defined in Codec.CBOR.Cuddle.Huddle Methods toType0 :: HuddleItem -> Type0 Source # | |
IsType0 Literal Source # | |
Defined in Codec.CBOR.Cuddle.Huddle | |
IsType0 Rule Source # | |
Defined in Codec.CBOR.Cuddle.Huddle | |
IsType0 Text Source # | |
Defined in Codec.CBOR.Cuddle.Huddle | |
IsType0 Integer Source # | |
Defined in Codec.CBOR.Cuddle.Huddle | |
IsType0 Double Source # | |
Defined in Codec.CBOR.Cuddle.Huddle | |
IsType0 Float Source # | |
Defined in Codec.CBOR.Cuddle.Huddle | |
IsType0 (Named Group) Source # | |
IsType0 (Value a) Source # | |
Defined in Codec.CBOR.Cuddle.Huddle |
comment :: HasField' "description" a (Maybe Text) => Text -> a -> a Source #
Add a description to a rule or group entry, to be included as a comment.
class CanQuantify a where Source #
opt :: CanQuantify a => a -> a Source #
Seal an array or map, indicating that it will no longer absorb (//). This is needed if you wish to include an array or map inside a top-level choice.
sarr :: ArrayChoice -> Seal Array Source #
Create and seal an array, marking it as accepting no additional choices
smp :: MapChoice -> Seal Map Source #
Create and seal a map, marking it as accepting no additional choices.
bstr :: ByteString -> Literal Source #
class IsConstrainable a x | a -> x Source #
Minimal complete definition
toConstrainable
Instances
IsConstrainable (Value a) a Source # | |
Defined in Codec.CBOR.Cuddle.Huddle Methods toConstrainable :: Value a -> Constrainable a |
class IsSizeable (a :: k) Source #
Marker that we can apply the size CtlOp to something. Not intended for export.
Instances
IsSizeable ByteString Source # | |
Defined in Codec.CBOR.Cuddle.Huddle | |
IsSizeable Text Source # | |
Defined in Codec.CBOR.Cuddle.Huddle | |
IsSizeable Int Source # | |
Defined in Codec.CBOR.Cuddle.Huddle |
cbor :: (IsCborable b, IsConstrainable c b) => c -> Rule -> Constrained Source #
tag :: Word64 -> a -> Tagged a Source #
Tag a CBOR item with a CDDL minor type. Thus, `tag n x` is equivalent to `#6.n(x)` in CDDL.
binding2 :: (IsType0 t0, IsType0 t1) => (GRef -> GRef -> Rule) -> t0 -> t1 -> GRuleCall Source #
Bind two variables as a generic call
collectFrom :: [HuddleItem] -> Huddle Source #
Collect all rules starting from a given point. This will also insert a single pseudo-rule as the first element which references the specified top-level rules.
collectFromInit :: [HuddleItem] -> Huddle Source #
Same as collectFrom
, but the rules passed into this function will be put
at the top of the Huddle, and all of their dependencies will be added at
the end in depth-first order.
toCDDLNoRoot :: Huddle -> CDDL Source #
Convert from Huddle to CDDL, skipping a root element.
(=:=) :: IsType0 a => Text -> a -> HuddleM Rule infixl 1 Source #
Overridden version of assignment which also adds the rule to the state
(=:~) :: Text -> Group -> HuddleM (Named Group) infixl 1 Source #
Overridden version of group assignment which adds the rule to the state
(=::=) :: IsType0 a => Text -> a -> Rule infixl 1 Source #
Renamed version of Huddle's underlying =:=
for use in generic bindings
setRootRules :: [Rule] -> HuddleM () Source #
huddleDef' :: HuddleM a -> (a, Huddle) Source #
include :: Includable a => a -> HuddleM a Source #
Include a rule, group, or generic rule defined elsewhere
unsafeIncludeFromHuddle :: Huddle -> Text -> HuddleM HuddleItem Source #