Christian Collberg
Department of Computer Science
University of Arizona
global x,y,z procedure p() x := x + y # integer addition x := x || y # string concatenation x := x ||| y # list concatenation end
int x;
String y;
float z;
void p() {
x = x + 5; /* integer addition */
z = z + 5.0; /* float addition */
y = y + "X"; /* string concatenation */
}
int A[20];
float x;
void p() {
A[5] = x;
A[x] = 5;
x = x + A;
}
global a,b
procedure p() {
a = new array [20]
...
b = new array [20]
...
a = a + b /* what operation is performed here? */
}
TYPE A = ARRAY [0..10] OF CHAR; TYPE B = ARRAY [0..10] OF CHAR; VAR a : A; VAR b : B; BEGIN a := b; (* legal? *) END
VAR a : float; VAR b : int; BEGIN a := a + b; END
global a,b,c
procedure p(x)
if x = 5 then
a := x
else
a := "hello"
write(a)
end
procedure main()
p(5)
end
class C {
void p() {
int x = new C();
}
}
int main() {
int* p = (int*) malloc (sizeof(int));
float f = *((float*) &p) + 3.14;
p = (int*)(*(int *)&f);
}
I spent a few weeks ...trying to sort out the terminology of strongly typed, statically typed, safe, etc., and found it amazingly difficult. ...The usage of these terms is so various as to render them almost useless.
My language is more strongly typed than your language.but harder to argue that
My language is strongly typed/statically typed, etc.
7#7
int main() {
int A[20];
int B[20];
A[25] = 5;
}
Negative indices were used in the old days to overwrite
the operating systems.
type Device is (Printer, Disk, Drum);
type Peripheral(Unit : Device := Disk) is record
case Unit is
when Printer => Line_Count : Integer ;
when others => Cylinder : CIndex;
end case;
end record;
function float2int is
new unchecked_conversion(float,integer);
...
f := float2int(i);
I, J : Integer range 1 .. 10 := 5; K : Integer range 1 .. 20 := 15; I := J; -- identical ranges K := J; -- compatible ranges J := K; -- will raise an exception if K>10
(define (sum l)
(cond
((null? l) 0)
((not (list? l))
(error "list expected"))
((not (number? (car l)))
(error "list of numbers expected"))
(else (+ (car l) (sum (cdr l))))
))
class A {}
class B extends A {
int x;
}
void p() {
B b = (B) new A();
}
procedure p (x : integer);
var z : real;
var c : char;
begin
write(x + z); /* convert x to real,
write a real */
write(c + z); /* type error */
end
len [] = 0 len _:xs = 1 + len xsthe Haskell translator will infer a most general type:
len :: [a] -> Int
{...,
"0",...,"9",...,
"A",...,"Z",...,
"a"...,"z",...}
END T = RECORD
a : real;
b : ARRAY ["a".."z"] OF SET OF char;
END;
INTERFACE Word; TYPE T = INTEGER; PROCEDURE Plus (x,y: T): T; PROCEDURE Times (x,y: T): T; PROCEDURE Minus (x,y: T): T; PROCEDURE Divide(x,y: T): T; PROCEDURE Mod(x,y: T): T; PROCEDURE LT(x,y: T): BOOLEAN; PROCEDURE LE(x,y: T): BOOLEAN; PROCEDURE GT(x,y: T): BOOLEAN; PROCEDURE GE(x,y: T): BOOLEAN; PROCEDURE And(x,y: T): T; PROCEDURE Or (x,y: T): T; PROCEDURE Xor(x,y: T): T; PROCEDURE Not (x: T): T; PROCEDURE Shift(x: T; n: INTEGER): T; PROCEDURE Rotate(x: T; n: INTEGER): T; PROCEDURE Extract(x: T; i, n: CARDINAL): T; PROCEDURE Insert(x: T; y: T; i, n: CARDINAL): T; END Word.