title: Polymorphic variant restriction in the variant definition
body: <p>Suppose that I want to model a simple expression type in OCaml:</p>
  
  <pre><code>type expr = 
  | `Int of int
  | `Str of string
  | `IntAdd of expr * expr
  | `StrAdd of expr * expr
  </code></pre>
  
  <p>Is it possible to restrict <code>expr</code> in <code>expr * expr</code> to specific constructors of <code>expr</code> itself (i.e. I'd like <code>IntExpr</code> to only allow 'Int's)? I can mimic this with pattern 
  matching but it gets cumbersome after <code>expr</code> expands. Can I somehow 
  use OCaml's type system to achieve this?</p>
  
  <p>I tried using polymorphic type upper bounds as follows:</p>
  
  <pre><code>type expr = 
  | `Int of int
  | `Str of string
  | `IntAdd of [&lt; `Int] * [&lt; `Int]
  | `StrAdd of [&lt; `Str] * [&lt; `Str]
  </code></pre>
  
  <p>but compiler does not accept this (with message <code>In case IntAdd of [&lt; Int ] * ([&lt; Int ] as 'a) the variable 'a is unbound</code>). Is there any trick to make this work?</p>