Algebraic data types: Difference between revisions

Content added Content deleted
(→‎{{header|jq}}: def node:)
Line 1,149: Line 1,149:
def E: []; # the empty node
def E: []; # the empty node


def binding(x): bindings({} | x) // empty;
def b(x): bindings({} | x) // empty;


# Input: [$color, $left, $value, $right]
# Input: [$color, $left, $value, $right]
def balance:
def balance:
(binding([B, [R, [R, {a}, {x}, {x}], {y}, {c}], {z}, {d}])
def node: [R, [B, .a, .x, .b], .y, [B, .c, .z, .d]];

| [R, [B, .a, .x, .b], .y, [B, .c, .z, .d]])
// (binding([B, [R, {a}, {x}, [R, {b}, {y}, {c}]], {z}, {d}])
(b([B, [R, [R, {a}, {x}, {x}], {y}, {c}], {z}, {d}]) | node)
| [R, [B, .a, .x, .b], .y, [B, .c, .z, .d] ])
// (b([B, [R, {a}, {x}, [R, {b}, {y}, {c}]], {z}, {d}]) | node)
// (binding([B, {a},{x}, [R, [R, {b}, {y}, {c}], {z}, {d}]])
// (b([B, {a},{x}, [R, [R, {b}, {y}, {c}], {z}, {d}]]) | node)
| [R, [B, .a, .x, .b], .y, [B, .c, .z, .d] ])
// (b([B, {a},{x}, [R, {b}, {y}, [R, {c}, {z}, {d}]]])| node)
// (binding([B, {a},{x}, [R, {b}, {y}, [R, {c}, {z}, {d}]]])
// (b([{col}, {a}, {x}, {b}])
| [R, [B, .a, .x, .b], .y, [B, .c, .z, .d] ])
| [.col, .a, .x, .b ]) ;
// (binding([{col}, {a}, {x}, {b}])
| [.col, .a, .x, .b ]) ;


# Input: a node
# Input: a node
Line 1,221: Line 1,219:
15
15
</pre>
</pre>



=={{header|Julia}}==
=={{header|Julia}}==