Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>No pattern matching as known from Haskell is built in into language, but D has very generic compile time and reflection capabilities that will allow you to match type and their structure in library. For matching runtime values you can use only ordinary <code>if</code> / <code>switch</code> ... constructs; <a href="http://d-programming-language.org/lazy-evaluation.html" rel="nofollow">lazy evaluation of function arguments</a> might also help with implementation of some matching-at-runtime techniques.</p> <p><a href="http://d-programming-language.org/template.html#Constraint" rel="nofollow">Template Constraints</a> will allow you to create function (template) overloads based on any expression evaluated at compile time (D allows you to execute almost all normal code during compilation). You can also use <code>static if</code> for similar effect. This will practically allow you to match type structure. This is also commonly used technique in D. </p> <p>You might find code of <a href="https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm.d" rel="nofollow">std.algorithm</a> interesting, look for isInputRange and similar functions - they perform matching on type structure - they restrict type of argument to be of certain <em>typeclass</em></p> <p>Some directions for compile time reflection:</p> <ul> <li><a href="http://d-programming-language.org/expression.html#IsExpression" rel="nofollow">Is Expression</a></li> <li><a href="http://d-programming-language.org/traits.html" rel="nofollow">Traits</a></li> <li><a href="http://d-programming-language.org/phobos/std_traits.html" rel="nofollow">std.traits</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload