title: Restrict Values of Type in Elm
body: <p>I'd like to define a type that represents a unit vector.</p>
  
  <p>This is what I have currently:</p>
  
  <pre><code>type UVec = UVec Float Float
  
  unit : Float -&gt; Float -&gt; UVec
  unit a b =
    let
      norm = sqrt (a^2 + b^2)
    in
      UVec (a/norm) (b/norm)
  </code></pre>
  
  <p>While <code>unit</code> yields what I want, I have no way of ensuring that <code>UVec</code> is always a unit vector in other parts of the program. For example, I could write something like this:</p>
  
  <p><code>wrong = UVec 100 200</code></p>
  
  <p>and it would compile just fine.</p>
  
  <p>Is there any way to make the <code>unit</code> function the sole constructor of the <code>UVec</code> type? Or some way to restrict values of <code>UVec</code>?</p>