Content deleted Content added
Minilexikon (talk | contribs) |
Minilexikon (talk | contribs) |
||
Line 45:
A tree pattern describes a part of a tree by starting with a node and specifying some branches and nodes and leaving some unspecified with a variable or wildcard pattern. It may help to think of the [[abstract syntax tree]] of a programming language and [[algebraic data type]]s.
====Haskell====
In Haskell, the following line defines an algebraic data type <code>Color</code> that has a single data constructor <code>ColorConstructor</code> that wraps an integer and a string.
Line 68 ⟶ 69:
The creations of these functions can be automated by Haskell's data [[Record (computer science)|record]] syntax.
====OCaml====
This [[OCaml]] example which defines a [[red–black tree]] and a function to re-balance it after element insertion shows how to match on a more complex structure generated by a recursive data type. The compiler verifies at compile-time that the list of cases is exhaustive and none are redundant.
|