title: Shared cases in F# discriminated unions
body: <p>I want to write something like this:</p>
  
  <pre><code>type NumExp = Num of float
  
  type Exp =
      | Num of float
      | Dot of NumExp * NumExp
      | Op of string * Exp * Exp
  
   let getValue (Num(n) : NumExp) = n
  </code></pre>
  
  <p>The compiler complains about a conflict between <code>NumExp</code> and <code>Exp</code> in <code>getValue</code>.
  Even the following fails:</p>
  
  <pre><code>let getValue (nn : NumExp) = match nn with | Num(n) -&gt; n
  </code></pre>
  
  <p><strong><em>Is there a way to use the same case in both discriminated unions that works with functions?</em></strong> The DU definitions themselves are OK.</p>
  
  <p>I want to use the same case to avoid adding a level of indirection like</p>
  
  <pre><code>type Exp =
      | NumExpExp of NumExp
      | Dot of NumExp * NumExp
      | Op of string * Exp * Exp
  </code></pre>
  
  <p>in the <code>Exp</code> definition.
  I feel I'm missing something very basic here.</p>
  
  <p>The reason I have <code>NumExp</code> is that I want to be able to 'plug' 2 <code>Exp</code>s into a <code>Dot</code> (rather than 2 floats) because it makes generating expressions easier, but they can't be any <code>Exp</code>, just numerical.</p>
  
  <p><strong>EDIT</strong>: what I really wanted to know is whether the two cases in the two DUs could be treated as the same entity (kind of like <code>Exp</code> "including" <code>NumExp</code>). I realise now <code>Exp.Num</code> and <code>NumExp.Num</code> are completely separate entities. Tomas provides a nice way of discriminating the two cases below.</p>