HORIZON HASKELLDocslts/ghc-9.14.xd82dee82026-10-12Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · d82dee8 · 2026-10-12

Modulecuddle-1.8.1.0GHC2021

Codec.CBOR.Cuddle.Huddle

Module for building CDDL in Haskell

Compared to the builders, this is less about creating a DSL for CDDL in Haskell as about using Haskell's higher-level capabilities to express CDDL constraints. So we ditch a bunch of CDDL concepts where we can instead use Haskell's capabilities there.

  • 12 types
  • 6 classes
  • 38 values
  • Packagecuddle-1.8.1.0
  • Exports66
  • LanguageGHC2021
  • LicenceApache-2.0
  • SourceHuddle.hs

Core Types

8 declarations
datadata Huddle
#

Top-level Huddle type is a list of rules.

Instances6IsList, Generic, Semigroup, Default, Rep, Item
  • IsList HuddleDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle

    This instance is mostly used for testing

  • Generic HuddleDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • Semigroup HuddleDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle

    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.

  • Default HuddleDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • type Rep Huddle = D1 ('MetaData "Huddle" "Codec.CBOR.Cuddle.Huddle" "cuddle-1.8.1.0-1n67ahaIhMs3FQkr3b5WBN" 'False) (C1 ('MetaCons "Huddle" 'PrefixI 'True) (S1 ('MetaSel ('Just "roots") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Rule]) :*: S1 ('MetaSel ('Just "items") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (OMap Name HuddleItem))))Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • type Item Huddle = RuleDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
datadata HuddleItem
#
Instances4Generic, HasName, IsType0, Rep
valuehuddleAugment :: Huddle -> Huddle -> Huddle
#

Joins two Huddle values with a left-bias. This means that this function is not symmetric and that any rules that are present in both prefer the definition from the Huddle value on the left.

datadata Rule
#
Instances9Generic, HasName, HasComment, HasGenerator, HasValidator, IsType0, …
datadata GroupDef
#
Instances6Generic, HasName, HasComment, IsType0, IsChoosable, Rep
classclass IsType0 a where
#

Methods

Instances21IsType0, …
  • IsType0 ByteStringDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 GRefDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 ArrayDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 ArrayChoiceDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 ConstrainedDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 GRuleCallDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 GroupDefDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 HuddleItemDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 LiteralDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 MapDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 MapChoiceDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 RangedDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 RuleDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 Type0Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 IntegerDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 DoubleDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 FloatDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 TextDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 (Choice Type2)Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 (Value a)Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 a => IsType0 (Tagged a)Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
datadata Value a where
#

Type-parametrised value type handling CBOR primitives. This is used to constrain the set of constraints which can apply to a given postlude type.

Instances4Show, IsType0, IsChoosable, IsConstrainable
  • Show (Value a)Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 (Value a)Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsChoosable (Value a) Type2Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsConstrainable (Value a) aDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
newtypenewtype Type0
#

Constructors

Instances4Num, IsType0, IsEntryLike, IsGroupOrArrayEntry
  • Num Type0Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 Type0Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsEntryLike Type0Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsGroupOrArrayEntry Type0Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle

AST extensions

14 declarations
datadata HuddleStage
#
Instances47IndexMappable, Eq, Show, Generic, Semigroup, Monoid, …
data familydata family XCddl i
#
Instances32IndexMappable, Eq, Ord, Show, Generic, Semigroup, …
data familydata family XTerm i
#
Instances39IndexMappable, Eq, Ord, Show, IsString, Generic, …
data familydata family XRule i
#
Instances31IndexMappable, Eq, Show, Generic, Semigroup, Monoid, …
data familydata family XXTopLevel i
#
Instances28IndexMappable, Eq, Ord, Show, Generic, Semigroup, …
data familydata family XXType2 i
#
Instances30IndexMappable, Eq, Ord, Show, Generic, Semigroup, …

Rules and assignment

3 declarations
valuecomment :: HasComment a => Comment -> a -> a
#

Add a description to a rule or group entry, to be included as a comment.

Maps

4 declarations
value(==>) :: (IsType0 a, IsEntryLike me) => Key -> a -> me
#
valuemp :: MapChoice -> MapChoice
#
valueidx :: Word64 -> Key
#

Use a number as a key

Arrays

2 declarations
valuea :: (IsType0 a, IsGroupOrArrayEntry e) => a -> e
#

Explicitly cast an item in an Array as an ArrayEntry.

valuearr :: ArrayChoice -> ArrayChoice
#

This function is used solely to resolve type inference by explicitly identifying something as an array.

Groups

2 declarations
newtypenewtype Group
#
Instances4IsList, Semigroup, Monoid, Item
  • IsList GroupDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • Semigroup GroupDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • Monoid GroupDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • type Item Group = ArrayEntryDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle

Quantification

2 declarations
classclass CanQuantify a where
#

Methods

  • (<+) :: Word64 -> a -> ainfixl 7

    Apply a lower bound

  • (+>) :: a -> Word64 -> ainfixr 6

    Apply an upper bound

Instances4CanQuantify
  • CanQuantify ArrayEntryDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • CanQuantify MapEntryDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • CanQuantify OccursDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • CanQuantify a => CanQuantify (Choice a)Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle

    A quantifier on a choice can be rewritten as a choice of quantifiers

Choices

6 declarations
classclass IsChoosable a b | a -> b where
#

Methods

Instances17IsChoosable, …
  • IsChoosable ByteString Type2Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsChoosable GRef Type2Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsChoosable ArrayChoice ArrayChoiceDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsChoosable Constrained Type2Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsChoosable GRuleCall Type2Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsChoosable GroupDef Type2Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsChoosable Literal Type2Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsChoosable MapChoice MapChoiceDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsChoosable Rule Type2Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsChoosable Type2 Type2Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsChoosable (Choice a) aDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsChoosable (Seal Array) Type2Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsChoosable (Seal ArrayChoice) Type2Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsChoosable (Seal Map) Type2Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsChoosable (Seal MapChoice) Type2Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsChoosable (Value a) Type2Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 a => IsChoosable (Tagged a) Type2Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
valuechoiceFromList :: IsChoosable a b => NonEmpty a -> Choice b
#

Takes a NonEmpty list of Huddle choosable terms and folds over them with (/) to create a Choice.

  choiceFromList $ NE.fromList $ [tag t (arr $ fromList [0 <+ a x]) | t <- [121 .. 127]]
value(/) :: (IsChoosable a c, IsChoosable b c) => a -> b -> Choice c
#

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.

valueseal :: a -> Seal a
#

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.

valuesarr :: ArrayChoice -> Seal Array
#

Create and seal an array, marking it as accepting no additional choices

valuesmp :: MapChoice -> Seal Map
#

Create and seal a map, marking it as accepting no additional choices.

Literals

5 declarations
datadata Literal
#
Instances5Show, HasComment, IsType0, IsRangeBound, IsChoosable
  • Show LiteralDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • HasComment LiteralDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsType0 LiteralDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsRangeBound LiteralDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsChoosable Literal Type2Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle

Ctl operators

5 declarations
classclass IsSizeable (a :: k)
#

Marker that we can apply the size CtlOp to something. Not intended for export.

Instances5IsSizeable
  • IsSizeable ByteStringDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsSizeable CGRefTypeDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsSizeable CRefTypeDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsSizeable IntDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsSizeable TextDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
valuesized
  1. :: (IsSizeable a, IsSize s, IsConstrainable c a)
  2. => c
  3. -> s
  4. -> Constrained
#

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.

Ranged

1 declaration
value(...) :: (IsRangeBound a, IsRangeBound b) => a -> b -> Ranged
#

Establish a closed range bound.

Tagging

1 declaration
valuetag :: Word64 -> a -> Tagged a
#

Tag a CBOR item with a CDDL minor type. Thus, `tag n x` is equivalent to `#6.n(x)` in CDDL.

Generics

6 declarations
newtypenewtype GRef
#

A reference to a generic parameter inside the body of a generic rule.

Instances6Show, IsType0, IsChoosable, IsConstrainable, IsCborable, IsComparable
  • Show GRefDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.CDDL
  • IsType0 GRefDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsChoosable GRef Type2Defined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsConstrainable GRef CGRefTypeDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsCborable GRefDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • IsComparable GRefDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle

Generators

1 declaration

Validators

1 declaration

Name

1 declaration
classclass HasName a where
#

Methods

Instances6HasName
  • HasName NameDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.CDDL
  • HasName AnyRefDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • HasName GRuleDefDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • HasName GroupDefDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • HasName HuddleItemDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle
  • HasName RuleDefined in cuddle-1.8.1.0 · Codec.CBOR.Cuddle.Huddle

Conversion to CDDL

4 declarations
valuecollectFrom :: [HuddleItem] -> Huddle
#

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.

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.