title: How to define Union polymorphic data structure's instance in Typed Racket?
body: <p>From The <a href="https://docs.racket-lang.org/ts-guide/types.html" rel="nofollow">Typed Racket Guide</a>, to define a Union Type, just use <code>(define-type Some-Type (U Type1 Type2))</code>.</p>
  
  <p>To define Polymorphic Data Structures, use something like <code>(define-type (Opt a) (U ...))</code>.</p>
  
  <p>I want to define a polymorphic binary tree</p>
  
  <pre><code>(define-type (Tree a) (U (Leaf a) Node))
  (struct (a) Leaf ([val : a]))
  (struct Node ([left : Tree] [right : Tree]))
  (define t1 (Leaf 5))
  (define t2 (Leaf 8))
  (define t3 (Node t1 t2))
  </code></pre>
  
  <p>I was wondering why the type of t1 is <code>Leaf</code> not <code>Tree</code>, and how to make it be a <code>Tree</code> ?</p>
  
  <pre><code>&gt; t1
  - : (Leaf Positive-Byte)
  #&lt;Leaf&gt;
  </code></pre>