Hacker News new | ask | show | jobs
by kssreeram 5811 days ago
Hi. Pointers to type T have the type Pointer[T]. '&' operator is for getting the address of a lvalue, and the '^' operator is for dereferencing. '^' is a better choice than C's '*' for dereferencing because, I can conveniently use the same operator for dereferenced field-access too, whereas C had to invent another operator "->" for that.

    record Point[T] {
        x : T;
        y : T;
    }
    
    updateViaPointer(ptr) {
        ptr^.x += 1;
        ptr^.y += 2;
    }
    
    test() {
        var p = Point(10, 20);  // type will be inferred as Point[Int]
        updateViaPointer(&p);
    }