... | @@ -248,7 +248,15 @@ Then we could write patterns like this: |
... | @@ -248,7 +248,15 @@ Then we could write patterns like this: |
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
This parses 3 bits to get the value of `n`, and then parses `n` bits to get the value of `val`. Note that this example uses the left-to-right scoping in the inner tuple: the first component is jused in the view expression in the second.
|
|
This parses 3 bits to get the value of `n`, and then parses `n` bits to get the value of `val`. Note that this example uses the left-to-right scoping in the inner tuple: the first component is used in the view expression in the second.
|
|
|
|
|
|
|
|
Note that this example could also be written without nesting as follows (suggested by AntC2):
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
parsePacket :: ByteString -> ...
|
|
|
|
parsePacket (p1 | Just (n, p2) <- bits 3 p1, Just (val, bs) <- bits n p2) = ...
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### N+k patterns
|
|
#### N+k patterns
|
|
|
|
|
... | | ... | |