View
131
Download
1
Category
Tags:
Preview:
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
UT
Aus
tin
Enso
William Cook, Alex LohUT Austin
Tijs van der StormCWI
UT
Aus
tin
Enable Good
2
Prevent Bad
UT
Aus
tin
Enable Good
Prevent Bad
Bug FindingRace DetectionType Checkingetc.
3
UT
Aus
tin
Enable Good
New languages?New features?
For what?
Prevent Bad
Bug FindingRace DetectionType Checkingetc.
UT
Aus
tin
Enable Good
New languages?New features?
For what?
Advantages:MeasurableDomain-free
Prevent Bad
Bug FindingRace DetectionType Checkingetc.
UT
Aus
tin
Kolmogorov Complexity
6
UT
Aus
tin
Shortest program that
generates information
7
UT
Aus
tin
Shortest program that
generates information
Best
behavior
8
UT
Aus
tin
Shortest program that
generates information
Best
behavior
Qualitative Kolmogorov Program Complexity
9
UT
Aus
tin
I don't know how
10
UT
Aus
tin
but it’s a good goal
11
UT
Aus
tin
A Problem
1. Many (many!) repeated instances of similar code
2. Unique details and names prevent generalization
12
UT
Aus
tin
13
Application(Code)
Behavior
Strategies(how)
Requirements (what)
UT
Aus
tin
14
Application(Code)
Application(Code)
Very differentCode Behavior
Very differentStrategies
Small change toRequirements
UT
Aus
tin
15
Application(Code)
Application(Code)
Very differentCode Behavior
Chaos!
Very differentStrategies
Small change toRequirements
UT
Aus
tin
16
Strategies(how)
Application(Code)
Reify!?
Behavior
Requirements (what)
UT
Aus
tin
17
Strategies
Requirements
Models
Behavior
Technical Requirements
UT
Aus
tin
18
DataManager
Data Requirements
DataModel
Objects
Technical Requirements
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
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
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
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
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
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
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
UT
Aus
tin
Quad-model
26
Nontrivial bootstrapping
UT
Aus
tin
27
Diagrams
• Model• Shapes and connectors
• Interpreter• Diagram render/edit application• Basic constraint solver
UT
Aus
tin
28
Schema Diagram
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
UT
Aus
tin
30
Schema Diagram Editor
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 }}}}
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]
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
UT
Aus
tin
34
How(implementation)
What(Specification)
Spectrum of programming
UT
Aus
tin
35
How(implementation)
What(Specification)
Verification
UT
Aus
tin
36
How(implementation)
What(Specification)
Synthesis
Verification
UT
Aus
tin
37
How(implementation)
What(Specification)
Synthesis
Domain-SpecificSpecifications
VerificationLite
VerificationVerification Lite = Type checking
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
UT
Aus
tin
Don't Design Your Programs
39
UT
Aus
tin
ProgramYour Designs
Ensoenso-lang.org
40
Recommended