Skip to content

Commit 6920b7e

Browse files
authored
Merge pull request #52 from ch1bo/ch1bo/docs-fixes
Markdown fixes and removed warning
2 parents d3d2796 + 9d328d9 commit 6920b7e

File tree

2 files changed

+32
-34
lines changed

2 files changed

+32
-34
lines changed

docs/huddle.md

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ defining CDDL in Huddle.
77

88
## Core Types
99
Huddle utilizes several core types to represent CDDL constructs:
10-
Huddle: The top-level type representing a collection of rules.
11-
HuddleItem: Represents individual items within a Huddle, such as rules, groups, or generic rules.
12-
Rule: A named type definition.
13-
Named: A type wrapper for associating a name, value, and optional description with an item.
14-
Value: A type representing primitive CBOR values.
15-
Group: Represents a collection of entries within a map or array.
10+
- Huddle: The top-level type representing a collection of rules.
11+
- HuddleItem: Represents individual items within a Huddle, such as rules, groups, or generic rules.
12+
- Rule: A named type definition.
13+
- Named: A type wrapper for associating a name, value, and optional description with an item.
14+
- Value: A type representing primitive CBOR values.
15+
- Group: Represents a collection of entries within a map or array.
1616

1717
## Language Extensions
1818

@@ -39,16 +39,18 @@ In addition, if using hlint, we suggest disabling the following hints:
3939
Rules are defined using the =:= operator. The left-hand side of the operator is
4040
the rule name (a T.Text value), and the right-hand side is the type definition.
4141

42-
ruleName =:= typeDefinition
42+
`ruleName =:= typeDefinition`
4343

4444
### Example:
45-
`age =:= VUInt`
45+
```haskell
46+
age =:= VUInt
47+
```
4648

4749
## Maps
4850
Maps are defined using the mp function and the ==> operator to specify key-value
4951
pairs.
5052

51-
mapName =:= mp [ key1 ==> value1, key2 ==> value2 ]
53+
`mapName =:= mp [ key1 ==> value1, key2 ==> value2 ]`
5254

5355
### Example:
5456
```haskell
@@ -61,26 +63,35 @@ location =:= mp [
6163
## Arrays
6264
Arrays are defined using the arr function and the a function to indicate array elements.
6365

64-
arrayName =:= arr [ a element1, a element2 ]
66+
`arrayName =:= arr [ a element1, a element2 ]`
6567

6668
### Example:
69+
```haskell
6770
point =:= arr [ a int, a int ]
71+
```
72+
6873
## Groups
6974
Groups are collections of entries within maps or arrays. They can be named using
7075
the =:~ operator.
7176

72-
groupName =:~ grp [ entry1, entry2 ]
77+
`groupName =:~ grp [ entry1, entry2 ]`
78+
7379
### Example:
7480
```haskell
7581
personalinfo =:~ grp [
7682
"name" ==> tstr,
7783
"age" ==> uint
7884
]
7985
```
86+
8087
## Choices
88+
8189
Huddle represents choices between types using the / operator.
90+
8291
### Example:
92+
```haskell
8393
value =:= int / tstr
94+
```
8495

8596
Huddle does not have a direct equivalent for the CDDL // operator (group
8697
choice). Instead, choices within arrays are represented by creating separate
@@ -96,9 +107,9 @@ choice =:= optionA / optionB
96107
## Quantifiers
97108
Huddle provides functions to specify occurrence quantifiers for group entries
98109
and array elements:
99-
● <+: Lower bound
100-
● +>: Upper bound
101-
opt: Optional (0 or 1 occurrences)
110+
- `<+`: Lower bound
111+
- `+>`: Upper bound
112+
- `opt`: Optional (0 or 1 occurrences)
102113

103114
### Example:
104115
```haskell
@@ -112,7 +123,7 @@ which will be included as comments in the generated CDDL.
112123
### Example:
113124
```haskell
114125
person =:= comment "Represents a person" $ mp [
115-
comment "Person's name" $ "name" ==> VBytes,
126+
"name" ==> VBytes & comment "Person's name",
116127
"age" ==> VUIntf
117128
]
118129
```
@@ -129,11 +140,11 @@ message = binding $ \t -> "message" =:= {
129140
```
130141

131142
## Converting to CDDL
132-
The toCDDL and toCDDLNoRoot functions convert a Huddle definition to CDDL.
133-
toCDDL generates a top-level root element, while toCDDLNoRoot skips the root
143+
The `toCDDL` and `toCDDLNoRoot` functions convert a Huddle definition to CDDL.
144+
`toCDDL` generates a top-level root element, while `toCDDLNoRoot` skips the root
134145
element.
135146

136147
## Example File (Conway.hs)
137-
The Conway.hs example file showcases a practical application of Huddle to define
138-
the CDDL for a specific data structure. The file defines numerous rules and
139-
groups using the Huddle syntax and functions described above.
148+
The `Conway.hs` example file showcases a practical application of Huddle to
149+
define the CDDL for a specific data structure. The file defines numerous rules
150+
and groups using the Huddle syntax and functions described above.

src/Codec/CBOR/Cuddle/CBOR/Gen.hs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ instance (RandomGen r) => RandomGenM (CapGenM r) r (M r) where
123123
applyRandomGenM f _ = state @"randomSeed" f
124124

125125
runGen :: M g a -> GenEnv g -> GenState g -> (a, GenState g)
126-
runGen (M m) env st = runReader (runStateT m st) env
126+
runGen m env st = runReader (runStateT (runM m) st) env
127127

128128
evalGen :: M g a -> GenEnv g -> GenState g -> a
129129
evalGen m env = fst . runGen m env
@@ -166,19 +166,6 @@ genBytes n = asksM @"fakeSeed" $ uniformByteStringM n
166166
genText :: forall g. (RandomGen g) => Int -> M g Text
167167
genText n = pure $ T.pack . take n . join $ repeat ['a' .. 'z']
168168

169-
--------------------------------------------------------------------------------
170-
-- Combinators
171-
--------------------------------------------------------------------------------
172-
173-
choose :: (RandomGen g) => [a] -> M g a
174-
choose xs = genUniformRM (0, length xs) >>= \i -> pure $ xs !! i
175-
176-
oneOf :: (RandomGen g) => [M g a] -> M g a
177-
oneOf xs = genUniformRM (0, length xs) >>= \i -> xs !! i
178-
179-
oneOfGenerated :: (RandomGen g) => M g [a] -> M g a
180-
oneOfGenerated genXs = genXs >>= choose
181-
182169
--------------------------------------------------------------------------------
183170
-- Postlude
184171
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)