Temporarily using the 'specialize-dict-key' branch from the stdlib which makes use of Pair where relevant. Once this is merged back into 'main' we should update the acceptance test toml files to keep getting them automatically upgraded. This commit also fixes an oversight in the reification of data-types now properly distinguishing between pairs and 2-tuples. Co-authored-by: Microproofs <kasey.white@cardanofoundation.org>
33 lines
526 B
Plaintext
33 lines
526 B
Plaintext
use aiken/builtin
|
|
|
|
type Foo {
|
|
A(Int)
|
|
B(Int, Int)
|
|
}
|
|
|
|
fn get_constr(data: Data) -> Int {
|
|
builtin.un_constr_data(data).1st
|
|
}
|
|
|
|
test foo() {
|
|
get_constr(A(42)) == 0 && get_constr(B(14, 42)) == 1
|
|
}
|
|
|
|
fn map(list: List<a>, f: fn(a) -> b) -> List<b> {
|
|
when list is {
|
|
[] ->
|
|
[]
|
|
[x, ..xs] ->
|
|
[f(x), ..map(xs, f)]
|
|
}
|
|
}
|
|
|
|
fn get_fields(data: Data) -> List<Int> {
|
|
builtin.un_constr_data(data).2nd
|
|
|> map(builtin.un_i_data)
|
|
}
|
|
|
|
test bar() {
|
|
get_fields(A(42)) == [42] && get_fields(B(14, 42)) == [14, 42]
|
|
}
|