Sistemas de tipos: lo bueno, lo malo y lo feo
Enrique Zamudio @chochosmx
github.com/chochos @ceylonlang
#Ceylon
• Programando desde 1982
• Profesionalmente desde 1994
• En Java desde 2000
• Proyectos FOSS
• j8583
• jAlarms
• Ceylon
Sistemas de tipos
• Todos los lenguajes tienen uno
• Una característica más?
• Nótese el término: SISTEMA
• Consideración superficial
Ceylon
• Creado a partir de un sistema de tipos
• Es una de sus características principales
• Sintaxis, gramática, operadores obedecen al ST
• Arreglar problemas comunes y/o graves en el sistema de tipos de Java
try { print(s.length()); } catch (NullPointerException ex) { System.out.println("Yay"); }
String s = null;
Object o = null; Integer i = null; List<String> l = null; PrintWriter p = null; WorkerThreadFactory wtf = null;
String s = null;
String|Integer? algo; if (exists algo) { print(algo.hash); if (is String algo) { print(algo.uppercased); } else { print(algo/2); } }
value a = 1; //Integer value b = "2"; //String value c = login("a","b"); //Usuario|Integer value d = a <=> 2; //Comparison
void enviar(Runnable r) { if (r instanceof Serializable) { stream.write((Serializable)r); } else { throw; } }
interface Runnalizable extends Runnable, Serializable { }
void enviar(Runnalizable r) { stream.write(r); }
private java.util.List<?> lista;
<T> void boom(java.util.List<T> l, T arg) { lista = l; lista.add(arg); }
Demo.java:7: error: no suitable method found for add(T) lista.add(arg); ^ method List.add(int,CAP#1) is not applicable (actual and formal argument lists differ in length) method List.add(CAP#1) is not applicable (actual argument T cannot be converted to CAP#1 by method invocation conversion) method Collection.add(CAP#1) is not applicable (actual argument T cannot be converted to CAP#1 by method invocation conversion) where T is a type-variable: T extends Object declared in method <T>boom(List<T>,T) where CAP#1 is a fresh type-variable: CAP#1 extends Object from capture of ?
Resumen• Tipos unión
• Tipos intersección
• Tipos enumerados
• Tipado por flujo / acotación de tipos
• Inferencia local de tipos
• Tipos denotables
Otras cosas
• Reified generics
• Varianza en el sitio de declaración
• Covarianza y contravarianza
• Tuplas