40
UT Austin Ens William Cook, Alex Loh UT Austin Tijs van der Storm CWI

Enso presented at Microsoft Research/CSW summer 2012

Embed Size (px)

DESCRIPTION

A version of a talk on Enso that I gave at Microsoft Research and CWI in 2012. http://www.enso-lang.org/

Citation preview

Page 1: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

Enso

William Cook, Alex LohUT Austin

Tijs van der StormCWI

Page 2: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

Enable Good

2

Prevent Bad

Page 3: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

Enable Good

Prevent Bad

Bug FindingRace DetectionType Checkingetc.

3

Page 4: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

Enable Good

New languages?New features?

For what?

Prevent Bad

Bug FindingRace DetectionType Checkingetc.

Page 5: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

Enable Good

New languages?New features?

For what?

Advantages:MeasurableDomain-free

Prevent Bad

Bug FindingRace DetectionType Checkingetc.

Page 6: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

Kolmogorov Complexity

6

Page 7: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

Shortest program that

generates information

7

Page 8: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

Shortest program that

generates information

Best

behavior

8

Page 9: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

Shortest program that

generates information

Best

behavior

Qualitative Kolmogorov Program Complexity

9

Page 10: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

I don't know how

10

Page 11: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

but it’s a good goal

11

Page 12: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

A Problem

1. Many (many!) repeated instances of similar code

2. Unique details and names prevent generalization

12

Page 13: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

13

Application(Code)

Behavior

Strategies(how)

Requirements (what)

Page 14: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

14

Application(Code)

Application(Code)

Very differentCode Behavior

Very differentStrategies

Small change toRequirements

Page 15: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

15

Application(Code)

Application(Code)

Very differentCode Behavior

Chaos!

Very differentStrategies

Small change toRequirements

Page 16: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

16

Strategies(how)

Application(Code)

Reify!?

Behavior

Requirements (what)

Page 17: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

17

Strategies

Requirements

Models

Behavior

Technical Requirements

Page 18: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

18

DataManager

Data Requirements

DataModel

Objects

Technical Requirements

Page 19: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

19

Using Managed Data (Ruby)

• Description of data to be managedPoint = { x: Integer, y: Integer }

• Dynamic creation based on metadatap = BasicRecord.new Point p.x = 3 p.y = -10print p.x + p.yp.z = 3 # error!

• Factory BasicRecord: Descrption<T> T

Page 20: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

20

Implementing Managed Data

• Override the "dot operator" (p.x)• Reflective handling of unknown methods• Ruby method_missing• Smalltalk: doesNotUnderstand• Also IDispatch, Python, Objective-C, Lua, CLOS• Martin Fowler calls it "Dynamic Reception"

• Programmatic method creation• E.g. Ruby define_method

• Partial evaluation

Page 21: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

21

Other Data Managers

• Mutability: control whether changes allowed• Observable: posts notifications• Constrained: checks multi-field invariants• Derived: computed fields (reactive)• Secure: checks authorization rules• Graph: inverse fields (bidirectional)• Persistence: store to database/external format• General strategy for all accesses/updates• Combine them for modular strategies

Page 22: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

Grammars

• Mapping between text and object graph• A point is written as (x, y)

• Notes:• Direct reading, no abstract syntax tree (AST)• Bidirectional: can parse and pretty-print• GLL parsing, interpreted!

Individual Grammar

(3, 4) P ::= [Point] "(" x:int "," y:int ")"

22

class fields

Page 23: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

23

start Opened

state Opened on close go Closed state Closed on open go Opened on lock go Locked

state Locked on unlock go Closed

def run_state_machine(m) current = m.start while gets puts "#{current.name}" input = $_.strip current.out.each do |trans| if trans.event == input current = trans.to break end end endend

StateMachineExample

class Machine start : State states! State*

class State machine: Machine name # str out ! Trans* in : Trans*

class Trans event : str from : State / out to : State / in

M::= [Machine] "start" \start:</states[it]> states:S*S ::= [State] "state" name:sym out:T*T ::= [Trans] "on" event:sym "go" to:</states[it]>

Door StateMachine StateMachine Grammar

StateMachine SchemaA StateMachine Interpreter

Page 24: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

24

3*(5+6)

module Eval operation :eval

def eval_Num(val) val end

def eval_Add(left, right) left.eval + right.eval end

def eval_Mul(left, right) left.eval * right.eval endend

ExpressionExample

class Exp

class Num val : int

class Add left : Exp right : Exp

class Mul left : Exp right : Exp

E ::= [Add] left:E "+" right:M | MM ::= [Mul] left:M "*" right:P | PP ::= [Num] val:int | "(" E ")"

Sample Expression Expression Grammar

Expression SchemaAn Expression Interpreter

Page 25: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

start GG ::= [Grammar] "start" start:</rules[it]> rules:R*R ::= [Rule] name:sym "::=" arg:AA ::= [Alt] alts:C+ @"|"C ::= [Create] "[" name:sym "]" arg:S | SS ::= [Sequence] elements:F*F ::= [Field] name:sym ":" arg:P | PP ::= [Lit] value:str | [Value] kind:("int" | "str" | "real" | "sym") | [Ref] "<" path:Path ">" | [Call] rule:</rules[it]> | [Code] "{" code:Expr "}" | [Regular] arg:P "*" Sep? { optional && many }

| [Regular] arg:P "?" { optional } | "(" A ")"

Sep ::= "@" sep:P

Grammar Grammar

25

non-terminal name reference to rule

Page 26: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

Quad-model

26

Nontrivial bootstrapping

Page 27: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

27

Diagrams

• Model• Shapes and connectors

• Interpreter• Diagram render/edit application• Basic constraint solver

Page 28: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

28

Schema Diagram

Page 29: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

29

Stencils

• Model: mapping object graph diagram• Interpreter• Inherits functionality of Diagram editor• Maps object graph to diagram–Update projection if objects change

• Maps diagram changes back to object graph• Binding for data and collections–Strategy uses schema information–Relationships get drop-downs, etc–Collections get add/remove menus

Page 30: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

30

Schema Diagram Editor

Page 31: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

31

Schema Stencildiagram(schema)graph [font.size=12,fill.color=(255,255,255)] {for "Class" class : schema.classes label class box [line.width=3, fill.color=(255,228,181)] { vertical { text [font.size=16,font.weight=700] class.name for "Field" field : class.defined_fields if (field.type is Primitive) horizontal { text field.name // editable field name text ": " text field.type.name // drop-down for type }}}}

Page 32: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

32

Schema Stencil: Connectors …// create the subclass links for class : schema.classes for "Parent" super : class.supers connector [line.width=3, line.color=(255,0,0)] (class --> super)…[also for relationships]

Page 33: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

Enso Summary

• Executable Specification Languages• Data, grammar, GUI, Web, Security, Queries, etc.

• External DSLs (not embeded)• Interpreters (not compilers/model transform)

• Multiple interpreters for each languages• Composition of Languages/Interpreters

• Reuse, extension, derivation (inheritance)• Self-implemented (Ruby for base/interpreters)

• Partial evaluation for speed33

Page 34: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

34

How(implementation)

What(Specification)

Spectrum of programming

Page 35: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

35

How(implementation)

What(Specification)

Verification

Page 36: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

36

How(implementation)

What(Specification)

Synthesis

Verification

Page 37: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

37

How(implementation)

What(Specification)

Synthesis

Domain-SpecificSpecifications

VerificationLite

VerificationVerification Lite = Type checking

Page 38: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

38

How(implementation)

What(Specification)

Synthesis (guided)

Domain-SpecificSpecifications

VerificationLite

SynthesisLite

Verification

Enso is "Synthesis Lite": Fully automated from domain-specific specification language

Page 39: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

Don't Design Your Programs

39

Page 40: Enso presented at Microsoft Research/CSW summer 2012

UT

Aus

tin

ProgramYour Designs

Ensoenso-lang.org

40