Skip to content

Conversation

nc6
Copy link
Collaborator

@nc6 nc6 commented Feb 14, 2024

We allow Haskell functions to be used as generic
rules by implementing the binding function.

Currently this is only implemented for one or two
generic parameters, but conceptually supports any
number.

Examples are provided both in the Conway.hs file
and in the tests. The generated CDDL for Conway
now looks like:

transaction_body = {0 : set<transaction_index>
                    , 1 : [* transaction_output]
                    , 2 : coin
                    , ? 3 : uint
                    , ? 4 : certificates
                    , ? 5 : withdrawals
                    , ? 7 : auxiliary_data_hash
                    , ? 8 : uint
                    , ? 9 : mint
                    , ? 11 : script_data_hash
                    , ? 13 : nonempty_set<transaction_input>
                    , ? 14 : required_signers
                    , ? 15 : network_id
                    , ? 16 : transaction_output
                    , ? 17 : coin
                    , ? 18 : nonempty_set<transaction_input>
                    , ? 19 : voting_procedures
                    , ? 20 : proposal_procedures
                    , ? 21 : coin
                    , ? 22 : positive_coin}

...

constr<a0> = #6.1([* a0])
              / #6.2([* a0])
              / #6.3([* a0])
              / #6.4([* a0])
              / #6.5([* a0])
              / #6.6([* a0])
              / #6.7([* a0])
              / #6.2([uint, [* a0]])

nonempty_set<a0> = set<a0>

set<a0> = [* a0]

We allow Haskell functions to be used as generic
rules by implementing the `binding` function.

Currently this is only implemented for one or two
generic parameters, but conceptually supports any
number.

Examples are provided both in the Conway.hs file
and in the tests. The generated CDDL for Conway
now looks like:

```
transaction_body = {0 : set<transaction_index>
                    , 1 : [* transaction_output]
                    , 2 : coin
                    , ? 3 : uint
                    , ? 4 : certificates
                    , ? 5 : withdrawals
                    , ? 7 : auxiliary_data_hash
                    , ? 8 : uint
                    , ? 9 : mint
                    , ? 11 : script_data_hash
                    , ? 13 : nonempty_set<transaction_input>
                    , ? 14 : required_signers
                    , ? 15 : network_id
                    , ? 16 : transaction_output
                    , ? 17 : coin
                    , ? 18 : nonempty_set<transaction_input>
                    , ? 19 : voting_procedures
                    , ? 20 : proposal_procedures
                    , ? 21 : coin
                    , ? 22 : positive_coin}
```

...

```
constr<a0> = #6.1([* a0])
              / #6.2([* a0])
              / #6.3([* a0])
              / #6.4([* a0])
              / #6.5([* a0])
              / #6.6([* a0])
              / #6.7([* a0])
              / #6.2([uint, [* a0]])

nonempty_set<a0> = set<a0>

set<a0> = [* a0]
```
@nc6
Copy link
Collaborator Author

nc6 commented Feb 14, 2024

@lehins FYI

@nc6 nc6 mentioned this pull request Feb 14, 2024
Copy link
Member

@lehins lehins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@nc6 nc6 merged commit 70cdf2e into master Feb 14, 2024
@nc6 nc6 deleted the nc/generics branch February 14, 2024 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants