title: Methods of storing weakly typed variables
body: <p>During the development stages of my compiler I ran into a pretty complex problem: how to store weakly typed variables in my language. </p>
  
  <p>Since I allow variables to be declared without explicitly specifying their type, and allow functions to return either type (e.g. function can return a scalar OR array), I am now facing the difficulty of what form to store these variables in.</p>
  
  <p>Here are the possibilities I've concidered, but all of them have a <strong>significant</strong> overhead:</p>
  
  <ul>
  <li>Regard all variables as lists of doubles (<code>List&lt;double&gt;</code>) and have the first element specify whether it's a scalar or array (<code>0</code> or <code>1</code> for instance).</li>
  <li>Regard all variables as <code>object</code> instances.</li>
  <li>Regard all variables as a <code>TVar</code> (custom class), which can be either a <code>double</code> or <code>List&lt;double&gt;</code>.</li>
  </ul>
  
  <p><strong>To keep in mind:</strong></p>
  
  <ul>
  <li>The only two types of variables I intend to have are doubles and double arrays, since all others can be derived from such (e.g. char is a case of a double, string is an array of chars, e.t.c.)</li>
  <li>I am using <code>ILAsm</code> which is a higher-level flavour of assembly (.NET intermediate language basically)</li>
  </ul>