title: F# pattern matching: how to match a set of possible types that share the same parameters?
body: <p>I'm new to F# and not quite familiar with the whole pattern matching idea.
  I tried to search for a better solution to my problem but I fear I can't even express the problem properly – I hope the question title is at least somewhat accurate.</p>
  
  <p>What I want to do is extract 2 "parameters" from <code>listMethod</code>.
  <code>listMethod</code> is of one of several types that have a string and an <code>Expression</code> "parameter" (I suspect parameter is the wrong term):</p>
  
  <pre><code>    let (varDecl, listExpr) =
          match listMethod with 
          | Select (var, expr)  -&gt; (var, expr)
          | Where (var, expr)   -&gt; (var, expr)
          | Sum (var, expr)     -&gt; (var, expr)
          | Concat (var, expr)  -&gt; (var, expr)
  </code></pre>
  
  <p>Then I continue to work with <code>varDecl</code> and at the end have a similar match expression with the actual listMethod code that makes use of several temporary variables I created based on <code>varDecl</code>.</p>
  
  <p>My question now is: How can I make the above code more compact? </p>
  
  <p>I want to match all those types that have 2 parameters (of type <code>string</code> and <code>Expression</code>) without listing them all myself, which is kinda ugly and hard to maintain.</p>
  
  <p>The <code>ListMethod</code> type is declared as follows (the whole thing is a FsLex/FsYacc project):</p>
  
  <pre><code>type ListMethod =
      | Select of string * Expr
      | Where of string * Expr
      | Sum of string * Expr
      | Concat of string * Expr
      | ...
      | somethingElse of Expr
  </code></pre>
  
  <p>(as of now I only have types of  the form <code>string * Expr</code>, but that will change).</p>
  
  <p>I reckon that this is a fairly dumb question for anyone with some experience, but as I've said I'm new to F# and couldn't find a solution myself.</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>Edit:</strong>  I'd really like to avoid listing all possible types of <code>listMethod</code> twice. If there's no way I can use wildcards or placeholders in the <code>match</code> expressions, perhaps I can modify the <code>listMethod</code> type to make things cleaner.</p>
  
  <p>One option that comes to mind would be creating only 1 type of <code>listMethod</code> and to create a third parameter for the concrete type (Select, Where, Sum).
  Or is there a better approach? </p>