SlideShare uma empresa Scribd logo
1 de 20
Baixar para ler offline
Model Manipulation
Using Embedded DSLs
in Scala
Filip Křikava
I3S laboratory, Université Nice Sophia-Antipolis
Scala Workshop 2013, Montpellier, 2.7.2013
Context
Model Manipulation
• Essential in Model-Driven Engineering (MDE)
• Automating operations such as
• model consistency checking
• model-to-model transformation (M2M)
• model-to-text transformation (M2T)
Approaches in
http://eclipse.org/modeling/
GPL external DSL
M2M
transformation
QVT
ETL
Kermeta
ATL
Model consistency
checking
OCL
EVL
Kermeta
M2T
transformation
MOFM2T
EGL
Kermeta
Xpand
Issues
✓ Versatility
✓ Tool support
✓ Performance
✓ Integration
✗ Limited tool support
✗ Limited performance
✗ Limited versatility (fall back to Java)
✗ Limited interoperability
✓ High level of abstraction
✓ Expressiveness and ease of use
✓ Domain-specific error checking and
optimizations
✗ Low level of abstraction
✗ Limited expressiveness (lack of
functional aspects in the language)
✗ Limited domain-specific error
checking and optimizations
= giving raise to accidental complexities, albeit of a different nature.
QVT
ETL
ATL
OCL
EVL
Kermeta
MOFM2T
EGL
Xpand
Towards Embedded DSLs
• External model manipulation DSLs
• embed general-purpose programming constructs into a specific
model-manipulation DSL
Towards Embedded DSLs
• External model manipulation DSLs
• embed general-purpose programming constructs into a specific
model-manipulation DSL
• We explore Internal / embedded model manipulation DSLs, that
• embed domain-specific model manipulation constructs into a
GPL
• aiming at
• similar features and expressiveness
• increased versatility
• improved tool support
• with significantly reduced engineering effort
Quick Example
Model Consistency Checking
Checking Library books’ ISBN codes.
context Book:
invariant UniqueISBN:
self.library.books->forAll(book |
book <> self implies book.isbn <> self.isbn);
OCL
Quick Example
Model Consistency Checking
Checking Library books’ ISBN codes.
✓ Tool support (rich editor, debugger)
✓ Unit testing
✓ Invariant inheritance
✓ Integration (build tools, workflows)
context Book:
invariant UniqueISBN:
self.library.books->forAll(book |
book <> self implies book.isbn <> self.isbn);
OCL
class BookContext extends ValidationContext
with BookPackageScalaSupport {
type Self = Class
def invUniqueISBN =
self.library.books forall { book =>
book != self implies book.isbn != self.isbn
}
}
Scala
Common Infrastructure Support
• Navigation
• Modification
self.getLibrary().getIsbn() self.library.isbn
self.library.books collect {
case Book(title, Author(author),_,_,_,_) => (title, author)
}
val sicp = Book(name = "SICP", copies = 2)
sicp.author = library.authors find (_.name == "H. Abelson")
with LibraryPackageScalaSupport
• Generate a Scala support trait for each EMF package
• Improving null handling
• Multiplicity 0..1 is wrapped into Option[T]
Model Consistency Checking
def invHasCapitalizedName =
// guards
guardedBy {
// invariant dependency
self satisfies invHasNonEmptyName
} check {
if (self.name.split(" ") forall (_(0).isUpper)) {
Passed
} else {
// detailed error messages
Error(s"Book ${self.name} does not have capitalized name")
// with quick fixes
.quickFix("Capitalize book name") {
self.name = self.name.split(" ") map (_.capitalize) mkString (" ")
}
}
}
✓ Context and invariant guards
✓ User feedback including quick fixes
✓ Invariant inheritance, modularity
✓ Different levels of severity
M2M Transformation
class OO2DB extends M2M with OOPackageScalaSupport with DBPackageScalaSupport {
def ruleClass2Table(cls: Class, tab: Table, pkey: Column) {
tab.name = cls.name;
tab.columns += pkey
tab.columns ++= ~cls.properties
pkey.name = "Id"
pkey.dataType = "Int"
}
@Lazy
def ruleProperty2Column(prop: Property, col: Column) = guardedBy {
!prop.multi
} transform {
col.name = prop.name
col.dataType = prop.type_.name
}
}
Simple object-oriented model into relational model
✓ Hybrid M2M transformation
✓ Rule inheritance, modularity
✓ Matched rules, lazy rules, partial rules
✓ Unit testing
M2M Transformation
class OO2DB extends M2M with OOPackageScalaSupport with DBPackageScalaSupport {
def ruleClass2Table(cls: Class, tab: Table, pkey: Column) {
tab.name = cls.name;
tab.columns += pkey
tab.columns ++= ~cls.properties
pkey.name = "Id"
pkey.dataType = "Int"
}
@Lazy
def ruleProperty2Column(prop: Property, col: Column) = guardedBy {
!prop.multi
} transform {
col.name = prop.name
col.dataType = prop.type_.name
}
}
Simple object-oriented model into relational model
✓ Hybrid M2M transformation
✓ Rule inheritance, modularity
✓ Matched rules, lazy rules, partial rules
✓ Unit testing
M2M Transformation
class OO2DB extends M2M with OOPackageScalaSupport with DBPackageScalaSupport {
def ruleClass2Table(cls: Class, tab: Table, pkey: Column) {
tab.name = cls.name;
tab.columns += pkey
tab.columns ++= ~cls.properties
pkey.name = "Id"
pkey.dataType = "Int"
}
@Lazy
def ruleProperty2Column(prop: Property, col: Column) = guardedBy {
!prop.multi
} transform {
col.name = prop.name
col.dataType = prop.type_.name
}
}
Executes
Simple object-oriented model into relational model
✓ Hybrid M2M transformation
✓ Rule inheritance, modularity
✓ Matched rules, lazy rules, partial rules
✓ Unit testing
M2T Transformation
class OO2Java extends M2T with OOPackageScalaSupport {
type Root = Class // input type for this transformation
def main =
!s"public class ${root.name}" curlyIndent {
!endl // extra new line
for (o <- root.operations) {
genOperation(o)
!endl // extra new line
}
}
def genOperation(o: Operation) =
!s"public ${o.returnType.name} ${o.name}()" curlyIndent {
!s"""
// TODO: should be implemented
throw new UnsupportedOperationException("${o.name}");
"""
}
}
Simple object-oriented model into Java code
✓ Template based, code-centric M2T
✓ Template inheritance, modularity
✓ Smart white space handling
✓ Unit testing
Further Work
Beyond Shallow Embedding
• Using Scala facilities for deep embedding
• scala-virtualized https://github.com/TiarkRompf/scala-virtualized
• lightweight modular staging http://scala-lms.github.io/
• For
• formal analysis
• domain-specific error checking
• domain-specific optimization
Further Work
Formal Reasoning
• Translating invariant expression into first-order logic
• To check invariant unsatisfiability1
library.books exists { book => book.pages > 300 }
library.books forall { book => book.pages < 300 }
1Clavel, M., Egea, M., Garcia de Dios, M.A. (2009) Checking unsatisfiability for OCL constraints. OCL Workshop,
MODELS 2009
• Automatic verification using SMT solvers
Further Work
Domain-Specific error checking
• Using ~ without corresponding rule yields compile time error
@implicitNotFound("No conversion rule between ${Source} and ${Target}.")
trait Rule[S <: EObject, T <: EObject]
implicit class EListM2MSupport[A <: EObject: ClassTag](that: EList[A]) {
def unary_~[B <: EObject](implicit rule: Rule[A, B]) = // ...
}
implicit val _ruleClass2Table = rule(ruleClass2Table _)
Further Work
Faster M2M Transformations
Translate declarative rules into imperative code
source.eAllContents collect {
case x: Class ⇒
ruleClass2Table(x, create[Table], create[Column])
case x: Property ⇒
ruleProperty2Column4(x, create[Column])
case x =>
logger warn (s"No rule to transform ${x}.")
}
class OO2DB extends M2M with OOPackageScalaSupport with DBPackageScalaSupport {
def ruleClass2Table(cls: Class, tab: Table, pkey: Column)
def ruleProperty2Column(prop: Property, col: Column)
}
Further Work
Even Faster M2M Transformations
Translate declarative rules into imperative code
class OO2DB extends M2M with OOPackageScalaSupport with DBPackageScalaSupport {
def ruleClass2Table(cls: Class, tab: Table, pkey: Column)
def ruleProperty2Column(prop: Property, col: Column)
}
val it = source.eAllContents
while (it.hasNext) {
val x = it.next
if (x.isInstanceOf[Class])
ruleClass2Table(x.asInstanceOf[Class], create[Table], create[Column])
else if (x.isInstanceOf[Property])
ruleProperty2Column4(x.asInstanceOf[Property], create[Column])
else
logger warn (s"No rule to transfrom ${x}.")
}
ThankYou
Filip Křikava
filip.krikava@i3s.unice.fr
https://fikovnik.github.io/Sigma
The work is partly funded by the ANR SALTY project under contract ANR-09-SEGI-012.
https://salty.unice.fr

Mais conteúdo relacionado

Mais procurados

The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論scalaconfjp
 
Oscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simpleOscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simpleMartin Odersky
 
Scala eXchange opening
Scala eXchange openingScala eXchange opening
Scala eXchange openingMartin Odersky
 
Clojure A Dynamic Programming Language for the JVM
Clojure A Dynamic Programming Language for the JVMClojure A Dynamic Programming Language for the JVM
Clojure A Dynamic Programming Language for the JVMelliando dias
 
Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuSalesforce Developers
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryPray Desai
 
Clojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp ProgrammersClojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp Programmerselliando dias
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdfHiroshi Ono
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101kankemwa Ishaku
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
Java Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & EncodingsJava Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & EncodingsAnton Keks
 
Scala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuScala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuHavoc Pennington
 
Ppl for students unit 4 and 5
Ppl for students unit 4 and 5Ppl for students unit 4 and 5
Ppl for students unit 4 and 5Akshay Nagpurkar
 

Mais procurados (18)

The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論
 
Oscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simpleOscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simple
 
Scala eXchange opening
Scala eXchange openingScala eXchange opening
Scala eXchange opening
 
Clojure A Dynamic Programming Language for the JVM
Clojure A Dynamic Programming Language for the JVMClojure A Dynamic Programming Language for the JVM
Clojure A Dynamic Programming Language for the JVM
 
Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and Heroku
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
Core java
Core javaCore java
Core java
 
Clojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp ProgrammersClojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp Programmers
 
Core java
Core javaCore java
Core java
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101
 
camel-scala.pdf
camel-scala.pdfcamel-scala.pdf
camel-scala.pdf
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Java Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & EncodingsJava Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & Encodings
 
Scala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuScala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on Heroku
 
Ppl for students unit 4 and 5
Ppl for students unit 4 and 5Ppl for students unit 4 and 5
Ppl for students unit 4 and 5
 
Presentation on java
Presentation  on  javaPresentation  on  java
Presentation on java
 

Destaque

A Self-Adaptive Evolutionary Negative Selection Approach for Anom
A Self-Adaptive Evolutionary Negative Selection Approach for AnomA Self-Adaptive Evolutionary Negative Selection Approach for Anom
A Self-Adaptive Evolutionary Negative Selection Approach for AnomLuis J. Gonzalez, PhD
 
Unisys Service Oriented Self Adaptive Systems
Unisys Service Oriented Self Adaptive SystemsUnisys Service Oriented Self Adaptive Systems
Unisys Service Oriented Self Adaptive SystemsGovCloud Network
 
Self-Adaptive Federated Authorisation Infrastructures
Self-Adaptive Federated Authorisation InfrastructuresSelf-Adaptive Federated Authorisation Infrastructures
Self-Adaptive Federated Authorisation InfrastructuresLionel Montrieux
 
ACTRESS: Domain-Specific Modeling of Self-Adaptive Software Architectures
ACTRESS: Domain-Specific Modeling of Self-Adaptive Software ArchitecturesACTRESS: Domain-Specific Modeling of Self-Adaptive Software Architectures
ACTRESS: Domain-Specific Modeling of Self-Adaptive Software ArchitecturesFilip Krikava
 
Intensive Surrogate Model Exploitation in Self-adaptive Surrogate-assisted CM...
Intensive Surrogate Model Exploitation in Self-adaptive Surrogate-assisted CM...Intensive Surrogate Model Exploitation in Self-adaptive Surrogate-assisted CM...
Intensive Surrogate Model Exploitation in Self-adaptive Surrogate-assisted CM...Ilya Loshchilov
 
Domain specific languages and Scala
Domain specific languages and ScalaDomain specific languages and Scala
Domain specific languages and ScalaFilip Krikava
 
Hausi Müller - Towards Self-Adaptive Software-Intensive Systems
Hausi Müller - Towards Self-Adaptive Software-Intensive SystemsHausi Müller - Towards Self-Adaptive Software-Intensive Systems
Hausi Müller - Towards Self-Adaptive Software-Intensive SystemsCHOOSE
 
A Self-Adaptive Deployment Framework for Service-Oriented Systems
A Self-Adaptive Deployment Framework for Service-Oriented SystemsA Self-Adaptive Deployment Framework for Service-Oriented Systems
A Self-Adaptive Deployment Framework for Service-Oriented SystemsSander van der Burg
 
Do Search-Based Approaches Improve the Design of Self-Adaptive Systems ? A Co...
Do Search-Based Approaches Improve the Design of Self-Adaptive Systems ? A Co...Do Search-Based Approaches Improve the Design of Self-Adaptive Systems ? A Co...
Do Search-Based Approaches Improve the Design of Self-Adaptive Systems ? A Co...Sandro Andrade
 
Architectural Design Spaces for Feedback Control in Self-Adaptive Systems Con...
Architectural Design Spaces for Feedback Control in Self-Adaptive Systems Con...Architectural Design Spaces for Feedback Control in Self-Adaptive Systems Con...
Architectural Design Spaces for Feedback Control in Self-Adaptive Systems Con...Sandro Andrade
 
Self-Adaptive SLA-Driven Capacity Management for Internet Services
Self-Adaptive SLA-Driven Capacity Management for Internet ServicesSelf-Adaptive SLA-Driven Capacity Management for Internet Services
Self-Adaptive SLA-Driven Capacity Management for Internet ServicesBruno Abrahao
 
201209 An Introduction to Building Affective-Driven Self-Adaptive Software
201209 An Introduction to Building Affective-Driven Self-Adaptive Software 201209 An Introduction to Building Affective-Driven Self-Adaptive Software
201209 An Introduction to Building Affective-Driven Self-Adaptive Software Javier Gonzalez-Sanchez
 
Self-adaptive Systems : An Introduction
Self-adaptive Systems : An Introduction Self-adaptive Systems : An Introduction
Self-adaptive Systems : An Introduction Sagar Sen
 

Destaque (14)

A Self-Adaptive Evolutionary Negative Selection Approach for Anom
A Self-Adaptive Evolutionary Negative Selection Approach for AnomA Self-Adaptive Evolutionary Negative Selection Approach for Anom
A Self-Adaptive Evolutionary Negative Selection Approach for Anom
 
Unisys Service Oriented Self Adaptive Systems
Unisys Service Oriented Self Adaptive SystemsUnisys Service Oriented Self Adaptive Systems
Unisys Service Oriented Self Adaptive Systems
 
Self-Adaptive Federated Authorisation Infrastructures
Self-Adaptive Federated Authorisation InfrastructuresSelf-Adaptive Federated Authorisation Infrastructures
Self-Adaptive Federated Authorisation Infrastructures
 
ACTRESS: Domain-Specific Modeling of Self-Adaptive Software Architectures
ACTRESS: Domain-Specific Modeling of Self-Adaptive Software ArchitecturesACTRESS: Domain-Specific Modeling of Self-Adaptive Software Architectures
ACTRESS: Domain-Specific Modeling of Self-Adaptive Software Architectures
 
Intensive Surrogate Model Exploitation in Self-adaptive Surrogate-assisted CM...
Intensive Surrogate Model Exploitation in Self-adaptive Surrogate-assisted CM...Intensive Surrogate Model Exploitation in Self-adaptive Surrogate-assisted CM...
Intensive Surrogate Model Exploitation in Self-adaptive Surrogate-assisted CM...
 
PhD Thesis Defense
PhD Thesis DefensePhD Thesis Defense
PhD Thesis Defense
 
Domain specific languages and Scala
Domain specific languages and ScalaDomain specific languages and Scala
Domain specific languages and Scala
 
Hausi Müller - Towards Self-Adaptive Software-Intensive Systems
Hausi Müller - Towards Self-Adaptive Software-Intensive SystemsHausi Müller - Towards Self-Adaptive Software-Intensive Systems
Hausi Müller - Towards Self-Adaptive Software-Intensive Systems
 
A Self-Adaptive Deployment Framework for Service-Oriented Systems
A Self-Adaptive Deployment Framework for Service-Oriented SystemsA Self-Adaptive Deployment Framework for Service-Oriented Systems
A Self-Adaptive Deployment Framework for Service-Oriented Systems
 
Do Search-Based Approaches Improve the Design of Self-Adaptive Systems ? A Co...
Do Search-Based Approaches Improve the Design of Self-Adaptive Systems ? A Co...Do Search-Based Approaches Improve the Design of Self-Adaptive Systems ? A Co...
Do Search-Based Approaches Improve the Design of Self-Adaptive Systems ? A Co...
 
Architectural Design Spaces for Feedback Control in Self-Adaptive Systems Con...
Architectural Design Spaces for Feedback Control in Self-Adaptive Systems Con...Architectural Design Spaces for Feedback Control in Self-Adaptive Systems Con...
Architectural Design Spaces for Feedback Control in Self-Adaptive Systems Con...
 
Self-Adaptive SLA-Driven Capacity Management for Internet Services
Self-Adaptive SLA-Driven Capacity Management for Internet ServicesSelf-Adaptive SLA-Driven Capacity Management for Internet Services
Self-Adaptive SLA-Driven Capacity Management for Internet Services
 
201209 An Introduction to Building Affective-Driven Self-Adaptive Software
201209 An Introduction to Building Affective-Driven Self-Adaptive Software 201209 An Introduction to Building Affective-Driven Self-Adaptive Software
201209 An Introduction to Building Affective-Driven Self-Adaptive Software
 
Self-adaptive Systems : An Introduction
Self-adaptive Systems : An Introduction Self-adaptive Systems : An Introduction
Self-adaptive Systems : An Introduction
 

Semelhante a Model Manipulation Using Embedded DSLs in Scala

Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scalashinolajla
 
Distributed Model Validation with Epsilon
Distributed Model Validation with EpsilonDistributed Model Validation with Epsilon
Distributed Model Validation with EpsilonSina Madani
 
How Scala promotes TDD
How Scala promotes TDDHow Scala promotes TDD
How Scala promotes TDDShai Yallin
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdfHiroshi Ono
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdfHiroshi Ono
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdfHiroshi Ono
 
JRuby e DSL
JRuby e DSLJRuby e DSL
JRuby e DSLjodosha
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java ProgrammersEric Pederson
 
Groovy concurrency
Groovy concurrencyGroovy concurrency
Groovy concurrencyAlex Miller
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at TwitterAlex Payne
 
Testing in Scala. Adform Research
Testing in Scala. Adform ResearchTesting in Scala. Adform Research
Testing in Scala. Adform ResearchVasil Remeniuk
 
Testing in Scala by Adform research
Testing in Scala by Adform researchTesting in Scala by Adform research
Testing in Scala by Adform researchVasil Remeniuk
 
Beyond Map/Reduce: Getting Creative With Parallel Processing
Beyond Map/Reduce: Getting Creative With Parallel ProcessingBeyond Map/Reduce: Getting Creative With Parallel Processing
Beyond Map/Reduce: Getting Creative With Parallel ProcessingEd Kohlwey
 
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...Andrew Phillips
 
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...Andrew Phillips
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San FranciscoMartin Odersky
 
Hey! There's OCaml in my Rust!
Hey! There's OCaml in my Rust!Hey! There's OCaml in my Rust!
Hey! There's OCaml in my Rust!Kel Cecil
 

Semelhante a Model Manipulation Using Embedded DSLs in Scala (20)

Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
 
Distributed Model Validation with Epsilon
Distributed Model Validation with EpsilonDistributed Model Validation with Epsilon
Distributed Model Validation with Epsilon
 
How Scala promotes TDD
How Scala promotes TDDHow Scala promotes TDD
How Scala promotes TDD
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
c++ Unit III - PPT.pptx
c++ Unit III - PPT.pptxc++ Unit III - PPT.pptx
c++ Unit III - PPT.pptx
 
JRuby e DSL
JRuby e DSLJRuby e DSL
JRuby e DSL
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java Programmers
 
Groovy concurrency
Groovy concurrencyGroovy concurrency
Groovy concurrency
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
Testing in Scala. Adform Research
Testing in Scala. Adform ResearchTesting in Scala. Adform Research
Testing in Scala. Adform Research
 
Testing in Scala by Adform research
Testing in Scala by Adform researchTesting in Scala by Adform research
Testing in Scala by Adform research
 
Beyond Map/Reduce: Getting Creative With Parallel Processing
Beyond Map/Reduce: Getting Creative With Parallel ProcessingBeyond Map/Reduce: Getting Creative With Parallel Processing
Beyond Map/Reduce: Getting Creative With Parallel Processing
 
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
 
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San Francisco
 
Week3
Week3Week3
Week3
 
Django Pro ORM
Django Pro ORMDjango Pro ORM
Django Pro ORM
 
Hey! There's OCaml in my Rust!
Hey! There's OCaml in my Rust!Hey! There's OCaml in my Rust!
Hey! There's OCaml in my Rust!
 

Último

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 

Último (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Model Manipulation Using Embedded DSLs in Scala

  • 1. Model Manipulation Using Embedded DSLs in Scala Filip Křikava I3S laboratory, Université Nice Sophia-Antipolis Scala Workshop 2013, Montpellier, 2.7.2013
  • 2. Context Model Manipulation • Essential in Model-Driven Engineering (MDE) • Automating operations such as • model consistency checking • model-to-model transformation (M2M) • model-to-text transformation (M2T)
  • 3. Approaches in http://eclipse.org/modeling/ GPL external DSL M2M transformation QVT ETL Kermeta ATL Model consistency checking OCL EVL Kermeta M2T transformation MOFM2T EGL Kermeta Xpand
  • 4. Issues ✓ Versatility ✓ Tool support ✓ Performance ✓ Integration ✗ Limited tool support ✗ Limited performance ✗ Limited versatility (fall back to Java) ✗ Limited interoperability ✓ High level of abstraction ✓ Expressiveness and ease of use ✓ Domain-specific error checking and optimizations ✗ Low level of abstraction ✗ Limited expressiveness (lack of functional aspects in the language) ✗ Limited domain-specific error checking and optimizations = giving raise to accidental complexities, albeit of a different nature. QVT ETL ATL OCL EVL Kermeta MOFM2T EGL Xpand
  • 5. Towards Embedded DSLs • External model manipulation DSLs • embed general-purpose programming constructs into a specific model-manipulation DSL
  • 6. Towards Embedded DSLs • External model manipulation DSLs • embed general-purpose programming constructs into a specific model-manipulation DSL • We explore Internal / embedded model manipulation DSLs, that • embed domain-specific model manipulation constructs into a GPL • aiming at • similar features and expressiveness • increased versatility • improved tool support • with significantly reduced engineering effort
  • 7. Quick Example Model Consistency Checking Checking Library books’ ISBN codes. context Book: invariant UniqueISBN: self.library.books->forAll(book | book <> self implies book.isbn <> self.isbn); OCL
  • 8. Quick Example Model Consistency Checking Checking Library books’ ISBN codes. ✓ Tool support (rich editor, debugger) ✓ Unit testing ✓ Invariant inheritance ✓ Integration (build tools, workflows) context Book: invariant UniqueISBN: self.library.books->forAll(book | book <> self implies book.isbn <> self.isbn); OCL class BookContext extends ValidationContext with BookPackageScalaSupport { type Self = Class def invUniqueISBN = self.library.books forall { book => book != self implies book.isbn != self.isbn } } Scala
  • 9. Common Infrastructure Support • Navigation • Modification self.getLibrary().getIsbn() self.library.isbn self.library.books collect { case Book(title, Author(author),_,_,_,_) => (title, author) } val sicp = Book(name = "SICP", copies = 2) sicp.author = library.authors find (_.name == "H. Abelson") with LibraryPackageScalaSupport • Generate a Scala support trait for each EMF package • Improving null handling • Multiplicity 0..1 is wrapped into Option[T]
  • 10. Model Consistency Checking def invHasCapitalizedName = // guards guardedBy { // invariant dependency self satisfies invHasNonEmptyName } check { if (self.name.split(" ") forall (_(0).isUpper)) { Passed } else { // detailed error messages Error(s"Book ${self.name} does not have capitalized name") // with quick fixes .quickFix("Capitalize book name") { self.name = self.name.split(" ") map (_.capitalize) mkString (" ") } } } ✓ Context and invariant guards ✓ User feedback including quick fixes ✓ Invariant inheritance, modularity ✓ Different levels of severity
  • 11. M2M Transformation class OO2DB extends M2M with OOPackageScalaSupport with DBPackageScalaSupport { def ruleClass2Table(cls: Class, tab: Table, pkey: Column) { tab.name = cls.name; tab.columns += pkey tab.columns ++= ~cls.properties pkey.name = "Id" pkey.dataType = "Int" } @Lazy def ruleProperty2Column(prop: Property, col: Column) = guardedBy { !prop.multi } transform { col.name = prop.name col.dataType = prop.type_.name } } Simple object-oriented model into relational model ✓ Hybrid M2M transformation ✓ Rule inheritance, modularity ✓ Matched rules, lazy rules, partial rules ✓ Unit testing
  • 12. M2M Transformation class OO2DB extends M2M with OOPackageScalaSupport with DBPackageScalaSupport { def ruleClass2Table(cls: Class, tab: Table, pkey: Column) { tab.name = cls.name; tab.columns += pkey tab.columns ++= ~cls.properties pkey.name = "Id" pkey.dataType = "Int" } @Lazy def ruleProperty2Column(prop: Property, col: Column) = guardedBy { !prop.multi } transform { col.name = prop.name col.dataType = prop.type_.name } } Simple object-oriented model into relational model ✓ Hybrid M2M transformation ✓ Rule inheritance, modularity ✓ Matched rules, lazy rules, partial rules ✓ Unit testing
  • 13. M2M Transformation class OO2DB extends M2M with OOPackageScalaSupport with DBPackageScalaSupport { def ruleClass2Table(cls: Class, tab: Table, pkey: Column) { tab.name = cls.name; tab.columns += pkey tab.columns ++= ~cls.properties pkey.name = "Id" pkey.dataType = "Int" } @Lazy def ruleProperty2Column(prop: Property, col: Column) = guardedBy { !prop.multi } transform { col.name = prop.name col.dataType = prop.type_.name } } Executes Simple object-oriented model into relational model ✓ Hybrid M2M transformation ✓ Rule inheritance, modularity ✓ Matched rules, lazy rules, partial rules ✓ Unit testing
  • 14. M2T Transformation class OO2Java extends M2T with OOPackageScalaSupport { type Root = Class // input type for this transformation def main = !s"public class ${root.name}" curlyIndent { !endl // extra new line for (o <- root.operations) { genOperation(o) !endl // extra new line } } def genOperation(o: Operation) = !s"public ${o.returnType.name} ${o.name}()" curlyIndent { !s""" // TODO: should be implemented throw new UnsupportedOperationException("${o.name}"); """ } } Simple object-oriented model into Java code ✓ Template based, code-centric M2T ✓ Template inheritance, modularity ✓ Smart white space handling ✓ Unit testing
  • 15. Further Work Beyond Shallow Embedding • Using Scala facilities for deep embedding • scala-virtualized https://github.com/TiarkRompf/scala-virtualized • lightweight modular staging http://scala-lms.github.io/ • For • formal analysis • domain-specific error checking • domain-specific optimization
  • 16. Further Work Formal Reasoning • Translating invariant expression into first-order logic • To check invariant unsatisfiability1 library.books exists { book => book.pages > 300 } library.books forall { book => book.pages < 300 } 1Clavel, M., Egea, M., Garcia de Dios, M.A. (2009) Checking unsatisfiability for OCL constraints. OCL Workshop, MODELS 2009 • Automatic verification using SMT solvers
  • 17. Further Work Domain-Specific error checking • Using ~ without corresponding rule yields compile time error @implicitNotFound("No conversion rule between ${Source} and ${Target}.") trait Rule[S <: EObject, T <: EObject] implicit class EListM2MSupport[A <: EObject: ClassTag](that: EList[A]) { def unary_~[B <: EObject](implicit rule: Rule[A, B]) = // ... } implicit val _ruleClass2Table = rule(ruleClass2Table _)
  • 18. Further Work Faster M2M Transformations Translate declarative rules into imperative code source.eAllContents collect { case x: Class ⇒ ruleClass2Table(x, create[Table], create[Column]) case x: Property ⇒ ruleProperty2Column4(x, create[Column]) case x => logger warn (s"No rule to transform ${x}.") } class OO2DB extends M2M with OOPackageScalaSupport with DBPackageScalaSupport { def ruleClass2Table(cls: Class, tab: Table, pkey: Column) def ruleProperty2Column(prop: Property, col: Column) }
  • 19. Further Work Even Faster M2M Transformations Translate declarative rules into imperative code class OO2DB extends M2M with OOPackageScalaSupport with DBPackageScalaSupport { def ruleClass2Table(cls: Class, tab: Table, pkey: Column) def ruleProperty2Column(prop: Property, col: Column) } val it = source.eAllContents while (it.hasNext) { val x = it.next if (x.isInstanceOf[Class]) ruleClass2Table(x.asInstanceOf[Class], create[Table], create[Column]) else if (x.isInstanceOf[Property]) ruleProperty2Column4(x.asInstanceOf[Property], create[Column]) else logger warn (s"No rule to transfrom ${x}.") }
  • 20. ThankYou Filip Křikava filip.krikava@i3s.unice.fr https://fikovnik.github.io/Sigma The work is partly funded by the ANR SALTY project under contract ANR-09-SEGI-012. https://salty.unice.fr