Commits

Shashank Bharadwaj committed bdaeb6f

adding the gradual typing part

Comments (0)

Files changed (1)

pycon-2013/slides.md

 	    getEngineByName("python");
 
         engine.eval("answer = 12 + 30");
-        Object x = engine.get("x");
-    	System.out.println("x: " + x);
+        Object x = engine.get("answer");
+    	System.out.println("Solve for x: " + x);
       }
     }
 
 
 Object Factories
 ================
+
+Gradual Typing
+==============
+
+* Originally proposed by Jeremy Siek and Walid Taha, extended by others
+* Optionally introduce static types into a dynamic language
+<!--*Optionally introduce dynamic type into a static language -->
+* Seamless integration between statically typed part and dynamically 
+  typed parts of the language
+* Promises that statically typed part will never raise a TypeError
+
+Gradual Typing for Python
+=========================
+
+* Prototype - in experimental mode!
+* `pip install gradual` to get it
+* Repo at:  `http://bitbucket.org/gradual/`
+
+Gradual Typing for Python
+=========================
+
+~~~~~
+from gradual import typed, obj, func
+
+@typed
+class YourAwesomeApi(object):
+    def answerToLife(self, a: int, b: int) -> int:
+        return a + b
+    
+def use_api(x: YourAwesomeApi):
+    print(x.answerToLife(10, 32))
+    print(x.answerToLife('hello', 'there'))
+    # TypeError: Expected int, got: 'hello' of type str
+
+    x.aNewFunction('hello world')
+
+use_api(YourAwesomeApi())
+~~~~~
+<!-- * Working on accurate representation of objects -->
+
+
+Future: Integrate Gradual Typing into Jython [1]
+================================================
+
+* Use Gradual Typing to enable direct importing of Python code in Java
+
+* Most Python code has one-one corrospondence with Java code
+* Drive type information to generate idiomatic Java code (where applicable)
+
+Future: Integrate Gradual Typing into Jython [2]
+================================================
+
+* More effieciently import Java code into Python
+
+* Java code could be treated as `typed` Python code.
+* Greatly reduce the cruft involved in importing Java code
+
+Future: Integrate Gradual Typing into Jython [2]
+================================================
+~~~~~~
+void type___setattr__(String name, PyObject value) {
+  PyObject field = lookup(name);
+  if ((field != null) && (field._doset(null, value)))
+      return;
+  if (modified == null) modified = Generic.set();
+  if (modified.add(name)) && (conflicted != null) {
+     for (PyJavaType conflict : conflicted) {
+      if (conflict.modified != null && 
+          conflict.modified.contains(name)) {
+        throw Py.TypeError("inconsistent");
+      }
+    }
+  }
+  object___setattr__(name, value);
+  postSetattr(name);
+ }
+~~~~~~
+
+Future: Integrate Gradual Typing into Jython [2]
+================================================
+
+* More effieciently import Java code into Python
+
+* Java code could be treated as `typed` Python code.
+* Greatly reduce the cruft involved in importing Java code
+
+<!-- because it looks more like Java-->