20-CS-4003-001 Organization of Programming Languages Fall 2017
Re-typing variables

Lambda calculus, Type theory, Formal semantics, Program analysis

    Prev     Next     All lectures

Can a variable's type be changed?

Java:
   
   public class intro_3 {
      public static void main (String args[]) {
         int p1 = 10;
         String p1 = "Hello World";
      }
   }

Answer for Java: No

Compiler results:

   intro_3.java:4: p1 is already defined in main(java.lang.String[])
   String p1 = "Hello World";
          ^
   1 error
 
Haskell:
   ghci> let p1 = 10;
   ghci> p1
   10
   ghci> let p1 = [1, 2, 11, 8, 3, 9, 10]
   ghci> p1
   [1,2,11,8,3,9,10]
Answer for Haskell: yes
 
Scheme:
   (let ((p1 10) (p1 '(1 2 3 4))) p1)

Answer for Scheme: No

Error on load:

   ;Loading "intro.3.ss"...
   ;lambda list has duplicate parameter: #[uninterned-symbol 11 p1] in
       (#[uninterned-symbol 11 p1] #[uninterned-symbol 11 p1])