+import Darwin
+
 // unsafe base
 
 protocol Vector {
     subscript( index: Int ) -> Float { get set }
+    var lensq: Float { get }
+    var length: Float { get }
 }
 
 struct Vec<T:Nat>: Vector {
     private var v = [Float]( count: T.literal(), repeatedValue: 0.0 )
     subscript( index: Int ) -> Float {
-        get {
-            return v[index]
+        get             { return v[index]     }
+        set( newValue ) { v[index] = newValue }
+    }
+    var lensq: Float {
+        var lensq: Float = 0.0
+        for n in 0...T.literal() - 1 {
+            lensq += v[n] * v[n]
         }
-        set( newValue ) {
-            v[index] = newValue
-        }
+        return lensq
+    }
+    init( v: [Float] ) {
+        self.v = Array( v[0...T.literal()] )
+    }
+    var length: Float {
+        return sqrt( self.lensq )
     }
 }
 

    init( x: Float, y: Float, z: Float, w: Float ) {
        self.v = [x,y,z,w]
    }
}

func dot<T:Nat>( a: Vec<T>, b: Vec<T> ) -> Float {

}

struct Vec2: Vector, SpecializedVector {
    let count = 2
    private var v = [Float]( count: 2, repeatedValue: 0.0 )
    subscript( index: Int ) -> Float {
        get             { return v[index]     }
