Jump to content

Algebraic data types: Difference between revisions

no edit summary
No edit summary
Line 8:
{{trans|Haskell}}
 
In E, a pattern can be used almost anywhere a variable name can. Additionally, there are two operators used for pattern matching idioms: <codett>=~</codett> (returns success as a boolean, somewhat like Perl's <codett>=~</codett>), and <codett>switch</codett> (matches multiple patterns, like Haskell's <codett>case</codett>).
 
Both of those operators are defined in terms of the basic bind/match operation: <codett>def <var>pattern</var> exit <var>failure_handler</var> := <var>specimen</var></codett>
 
def balance(tree) {
Line 51:
=={{header|Haskell}}==
 
<codelang lang="haskell">
data Color = R | B
data Tree a = E | T Color (Tree a) a (Tree a)
Line 70:
| otherwise = s
T _ a y b = ins s
</codelang>
 
=={{header|OCaml}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.