.NET Programming Language Research @ MSR Cambridge Nick Benton Microsoft Research Cambridge
Slide 2MSR Cambridge Programming Principles and Tools Group Luca Cardelli Nick Benton Cedric Fournet Andy Gordon Tony Hoare Andrew Kennedy Simon Peyton Jones Don Syme Simon Marlow Claudio Russo Mark Shields + guests, PhD understudies, assistants,… MS.NET days March 2002
Slide 3.NET in MSR Programming Principles and Tools Group Verifier spec (POPL) CLR plan criticism Project 7 (Babel) SML.NET (ICFP,ICFP,HOOTS) Generics for C# and .NET (PLDI) Extended IL (Babel) Polyphonic C# (FOOL, ECOOP) Stack-Walking Security examination (POPL) Assertions MS.NET days March 2002
Slide 4Part 1 SML.NET Nick Benton, Andrew Kennedy and Claudio Russo
Slide 5Advanced Programming Languages on the CLR .NET and the CLR give an incredible chance to programming dialect creators and implementers: The runtime gives administrations (execution motor, junk accumulation,… ) which make delivering a decent usage of your dialect less demanding The systems & libraries mean you can really do valuable things with your new dialect (design, organizing, database get to, web administrations,… ) Multi-dialect segment based programming makes it considerably more pragmatic for other individuals to utilize your dialect in their own particular undertakings MS.NET days March 2002
Slide 6Our most loved dialect: Standard ML A protected, measured, strict, higher-arrange, practical , polymorphic programming dialect with order time sort checking and sort surmising, rubbish gathering, special case taking care of, permanent information sorts , design coordinating and updatable references, dynamic information sorts, and parametric modules. with a few effective executions and a formal definition with a proof of soundness. (Scheme+types+real sentence structure, Haskell with call by esteem assessment) MS.NET days March 2002
Slide 7Some SML datatype arrange = LESS | GREATER | EQUAL datatype 'a Tree = Empty | Node of 'a * ('a Tree) * ('a Tree) fun contains analyze (x, Empty) = false | contains look at (x, Node(v, left, right)) = (case think about (x,v) of LESS => contains think about (x,left) | GREATER => contains think about (x, right) | EQUAL => genuine ) contains : ('a * 'a - > arrange) - > ('a * 'a Tree) - > bool MS.NET days March 2002
Slide 8What is SML.NET? Compiler for SML that objectives certain CIL Research Issues: Can we arrange a polymorphic useful dialect to a monomorphic, question situated runtime? Yes How would we be able to make it deliver quick, minimized code? Entire program advancing compiler. Monomorphisation. Representation traps. Novel wrote middle of the road dialect utilizing monads to track symptoms. By what means would we be able to make cross-dialect working simple? We stretch out SML to bolster the majority of the .NET CLS (Common Language Specification), giving smooth bidirectional interoperability .NET structure libraries & other .NET dialects MS.NET days March 2002
Slide 9Previous ways to deal with interop Bilateral interface with marshaling and unequivocal calling traditions (e.g. JNI, O'Caml interface for C). Cumbersome, monstrous, attached to one execution, just for specialists Multilateral interface with IDL (e.g. COM, CORBA) together with specific dialect mappings (e.g. H/Direct, Caml COM, MCORBA). Need to compose IDL and utilize instruments, have a tendency to be most minimized shared factor, memory administration regularly dubious MS.NET days March 2002
Slide 10Interop in .NET Languages share a typical larger amount framework (CLR): shared store implies no precarious cross-pile pointers (cf reference numbering in COM) shared sort framework implies no marshaling (cf string<- >char* marshaling for Java<- >C) shared special case display bolsters cross-dialect exemption taking care of MS.NET days March 2002
Slide 11SML.NET interop Sounds extraordinary, however SML is not question situated So we will need to do some work… Possible ways to deal with interop: don't develop dialect; rather give wrappers that give an utilitarian perspective of a CLS library (Haskell, Mercury). Effective utilitarian sort frameworks can go far towards demonstrating OO sort frameworks upgrade the dialect (OO-SML?) Our approach – a center way: re-utilize existing elements where proper (non-question situated subset) expand dialect for advantageous interop when "fit" is terrible (protest arranged elements) live with the CLS at limits: don't attempt to fare complex ML sorts to different dialects (what might they do with them?) MS.NET days March 2002
Slide 12Re-utilize SML highlights various args tuple void unit invalid NONE static field val restricting SML static technique fun restricting CLS namespace structure appoint five star work impermanence ref utilizing open private fields neighborhood decls MS.NET days March 2002
Slide 13Extend dialect sort test cast designs class definitions classtype occurrence strategy conjuring obj.#meth case field get to obj.#fld custom qualities properties in classtype throws exp :> ty CLS SML MS.NET days March 2002
Slide 14Extract from WinForms interop open System.Windows.Forms System.Drawing System.ComponentModel fun selectXML () = let val fileDialog = OpenFileDialog() in fileDialog.#set_DefaultExt("XML"); fileDialog.#set_Filter("XML documents (*.xml) |*.xml"); if fileDialog.#ShowDialog() = DialogResult.OK then case fileDialog.#get_FileName() of NONE => () | SOME name => replaceTree (ReadXML.make name, "XML record '" ^ name ^ "'") else () end no args = ML unit esteem CLS Namespace = ML structure static technique = ML work static steady field = ML esteem occasion technique summon CLS string = ML string invalid esteem = NONE And note that there are no express sorts in this code MS.NET days March 2002
Slide 15Ray following in ML ICFP programming rivalry: manufacture a beam tracer in less than 3 days 39 sections in a wide range of dialects: C, C++, Clean, Dylan, Eiffel, Haskell, Java, Mercury, ML, Perl, Python, Scheme, Smalltalk ML (Caml) was in 1 st and 2 nd put MS.NET days March 2002
Slide 16Ray following in SML.NET Translate winning passage to SML Add WinForms interop Run on .NET CLR Performance on this illustration twice on a par with mainstream enhancing local compiler for SML (however on others we're twice as awful) MS.NET days March 2002
Slide 17Visual Studio Integration Bootstrap the compiler to deliver a .NET segment for parsing, typechecking, and so forth of SML Use interlanguage working expansions to uncover that as a COM segment which can be stuck into Visual Studio Write new ML code to handle language structure highlighting, tooltips, blunder reporting, and so on. MS.NET days March 2002
Slide 18Part 2 Generics in the CLR and C# Andrew Kennedy and Don Syme
Slide 19Note: This is not in V1 of the CLR It will be in V2 MS.NET days March 2002
Slide 20Part 1: Introduction MS.NET days March 2002
Slide 21What are generics? Sorts which are parameterized by different sorts, e.g. Stack<int> , Stack<string> Generics, layouts, parametric polymorphism Ada, Eiffel, C++, ML, Haskell, Mercury, Component Pascal,… Promote code reuse, increment sort wellbeing, better execution Good for accumulations, higher-arrange programming and by and large building more elevated amount, reusable reflections MS.NET days March 2002
Slide 22Generic code in C# today (1) class Stack { private Object [] things; private int nitems; Stack() { nitems = 0; things = new Object [50]; } Object Pop() { if (nitems == 0) toss new EmptyException(); return items[- - nitems]; } void Push( Object thing) { ... return items[nitems++]; } MS.NET days March 2002
Slide 23Generic code in C# today (2) Stack s = new Stack(); s.Push(1); s.Push(2); int n = (int)(s.Pop()) + (int)(s.Pop()); What's the matter with that? It's vacant . Sort framework doesn't report what ought to be in a specific stack. It's risky . Sort blunders ( s.Push("2"); ) prompt to runtime special cases as opposed to being gotten by compiler It's appalling . Throws all around. It's moderate . Throws are moderate, and changing over base sorts (e.g. ints) to Objects includes costly boxing. MS.NET days March 2002
Slide 24Generic code in C# tomorrow (1) class Stack <T> { private T[] things; private int nitems; Stack() { nitems = 0; things = new T[50] ; } T Pop() { if (nitems == 0) toss new EmptyException(); return items[- - nitems]; } void Push( T thing) { if (items.Length == nitems) { T[] temp = things; things = new T[nitems*2]; Array.Copy<T> (temp, things, nitems); } items[nitems++] = thing; } MS.NET days March 2002
Slide 25Generics: vast plan space But can sort instantiations can be non-reference? Set<int> List<float> Parameterized classes, interfaces, and techniques e.g. Do you delete sorts at runtime? /two-parameter class Dict<K,D> { ... } /parameterized interface IComparable<T> { ... }/parameterized struct Pair<A,B> { ... } /nonexclusive strategy T[] Slice<T>(T[] arr, int begin, int number) Do we have correct runtime sort data? in the event that (x is Set<int>) .... Do you share code? Requirements? class C<T: IFoo, IBar> { ... } What goes in the CLR? What goes in the compilers? MS.NET days March 2002
Slide 26Ge neric interfaces interface IDictionary<K,D> { D Lookup(K); ... } class Dictionary<K,D> : IDictionary<K,D> { D Lookup(K); ... } Dictionary<String,String> MS.NET days March 2002
Slide 27G eneric strategies A non specific technique is only a group of strategies, recorded by sort. static void Sort<T> (T[]) { ... } int[] x = { 5,4,3,2 }; Sort(x); MS.NET days March 2002
Slide 28Explicit C onstraints interface IComparable<T> { sta
SPONSORS
SPONSORS
SPONSORS