Modular Design of Domain-Specific Languages using Splittings of - - PowerPoint PPT Presentation

modular design of domain specific languages using
SMART_READER_LITE
LIVE PREVIEW

Modular Design of Domain-Specific Languages using Splittings of - - PowerPoint PPT Presentation

Modular Design of Domain-Specific Languages using Splittings of Catamorphisms Eric Badouel and Rodrigue Aim e Djeumen Djatcha Inria - Rennes, France and Univ. Douala, Cameroon ICTAC 2018, Stellenbosch, South Africa E. Badouel, R. Djeumen


slide-1
SLIDE 1

Modular Design of Domain-Specific Languages using Splittings of Catamorphisms

Eric Badouel and Rodrigue Aim´ e Djeumen Djatcha

Inria - Rennes, France and Univ. Douala, Cameroon

ICTAC 2018, Stellenbosch, South Africa

  • E. Badouel, R. Djeumen (Inria & Univ. Douala)

Modular Design of DSLs ICTAC 2018, Stellenbosch 1 / 16

slide-2
SLIDE 2

Domain specific languages

Domain Specific Languages

Language-oriented approach to modularity Design a domain specific language (DSL) by packaging reusable domain knowledge into language features. Develop a specific application by writing a program in this DSL. Domain Specific Embedded Languages (DSEL) P. Hudak The DSEL inherits from its host language features not specific to the domain. It also inherits the tools used as a support to programming (edition, type checking, compilation ...). Several DSELs can communicate through their shared host language. Haskell is a good host language

DSL for denotational semantics. Monadic computations.

  • E. Badouel, R. Djeumen (Inria & Univ. Douala)

Modular Design of DSLs ICTAC 2018, Stellenbosch 2 / 16

slide-3
SLIDE 3

A language of boxes

Example: A language of boxes

y−coord

hb vl vr hb vl ht

(0,0) x−coord

A box is either an elementary box (with a unit size: its depth and height is one) or is obtained by composing two sub-boxes. Two boxes can be composed either vertically with a left (vl) or a right (vr) alignement or horizontally with a top (ht)

  • r bottom (hb) alignment.
  • E. Badouel, R. Djeumen (Inria & Univ. Douala)

Modular Design of DSLs ICTAC 2018, Stellenbosch 3 / 16

slide-4
SLIDE 4

A language of boxes

The semantic domain is given by attributes

We assign a set of attributes to each sort Inherited attribute: position of its origin. Synthesized attributes: size ot the box and the origin of the elementary boxes it contains. Semantic interpretation of a box:

data Size = Size {depth , height :: Double} deriving Show data Point = Point {xcoord, ycoord :: Double} deriving Show data Box = Box{list :: Point -> [Point] ,size :: Size}

  • E. Badouel, R. Djeumen (Inria & Univ. Douala)

Modular Design of DSLs ICTAC 2018, Stellenbosch 4 / 16

slide-5
SLIDE 5

A language of boxes

The Interpretation functions are given by semantic rules

semantic rules elembox = SBox (\ pt → [pt])(Size 1 1) hb box1 box2 = SBox list’ size’ where list’ pt = (list box1 (pi1 pt))++(list box2 (pi2 pt)) size’ = Size (d1 + d2)(max h1 h2) pi1 (Point x y) = Point x (y + (max (h2-h1) 0)) pi2 (Point x y) = Point x (y + (max (h1-h2) 0)) Size d1 h1 = size box1 Size d2 h2 = size box2 ...

  • E. Badouel, R. Djeumen (Inria & Univ. Douala)

Modular Design of DSLs ICTAC 2018, Stellenbosch 5 / 16

slide-6
SLIDE 6

A language of boxes

Application Programming Interface (API) of the DSL

The description of datatype Box is not exported (abstract data type) Functions that allows to use a box (destructors): size :: Box → Size list :: Box → Point → [Point] Functions that allows to build a box (constructors): ebox :: Box hb, ht, vt, vb :: Box → Box → Box For example: size (hb (vl (hb ebox ebox) ebox) (vr ebox (vl ebox (ht ebox ebox)))) = Size{depth =4, height =3}

  • E. Badouel, R. Djeumen (Inria & Univ. Douala)

Modular Design of DSLs ICTAC 2018, Stellenbosch 6 / 16

slide-7
SLIDE 7

A language of boxes

Extending a Domain Specific Language

By adding new destructors and/or constructors in a conservative way: The expression problem (Philip Walder) The goal is to define a data type by cases, where one can add new cases to the data type and new functions over the datatype, without recompiling existing code, and while retaining static type safety. A solution: Wouter Swierstra, data types ` a la carte. But sometimes we need to refactor more drastically the domains of interpretation and one cannot reuse the existing implementation, eg

data Box = Image {image :: Point -> Maybe Color, bb :: Size}

  • E. Badouel, R. Djeumen (Inria & Univ. Douala)

Modular Design of DSLs ICTAC 2018, Stellenbosch 7 / 16

slide-8
SLIDE 8

Algebras and modular decomposition

Algebras

Multi-sorted signature Σ = (S, Ω) (syntax):

a set of sorts s ∈ S; a set of operators ω ∈ Ω(s1 · · · sn, s) with arities and sort.

A Σ-algebra (A, ϕ) (interpretation)

a domain of interpretation As for each s ∈ S; a set of interpretation functions ωϕ :: As1 · · · Asn → As for each ω ∈ Ω(s1 · · · sn, s).

Letting A = ζ × α (ζ for the parameters), an algebra is a morphism ϕ : Fζα → α for the (parametric) polynomial functor F : |Set|p+n → |Set|n where F(X)s =

  • ω∈Ω(s1···sn,s)

Xs1 × . . . × Xsn the free algebra (of terms) F †ζ (note: F † is called the type functor associated with F) satisfies a natural isomorphism Fζ

  • F †ζ

∼ = F †ζ. F †ζ is the initial algebra, hence the canonical morphism of algebras ( [ϕ] )F,ζ : F †ζ → α (catamorphism).

  • E. Badouel, R. Djeumen (Inria & Univ. Douala)

Modular Design of DSLs ICTAC 2018, Stellenbosch 8 / 16

slide-9
SLIDE 9

Algebras and modular decomposition

Continuous Algebras

Haskell functions are however interpreted in the category H = DCPO⊥ of pointed dcpos and continuous functions. Which does not have coproducts The subcategory C = DCPO⊥! of pointed dcpos and strict continuous functions.

Finite products are given by the cartesian products Finite coproduct of two dcpos is their coalesced sum A ⊕ B

The lifting operator (−)⊥ consists in adding a new least element to a given dcpo: A⊥ = A ⊎ {⊥}. The sum of pointed dcpos be given by

1≤i≤n Ai = (A1)⊥ ⊕ · · · ⊕ (An)⊥ or

equivalently by

1≤i≤n Ai = (A1 ⊎ · · · ⊎ An)⊥. NOT ASSOCIATIVE.

C(A⊥, B) ∼ = H(A, B) hence C(

  • 1≤i≤n

Ai, B) = C(⊕1≤i≤n(Ai)⊥, B) ∼ =

  • 1≤i≤n

C((Ai)⊥, B) ∼ =

  • 1≤i≤n

H(Ai, B)

  • E. Badouel, R. Djeumen (Inria & Univ. Douala)

Modular Design of DSLs ICTAC 2018, Stellenbosch 9 / 16

slide-10
SLIDE 10

Algebras and modular decomposition

Algebras in Haskell

The Haskell data type definition

data Tree a = Node a (Forest a) data Forest a = Leaf | Cons (Tree a) (Forest a)

is associated with the (parametric) polynomial functor F : C3 → C2 given by F(A, T, F) = ((A × F)⊥, 1 + (T × F)) An F-algebra ϕ : Fζα → α is a continuous Σ-algebra

data Alg a t f = Alg {node :: a -> f -> t, leaf :: f, cons :: t -> f -> t}

  • E. Badouel, R. Djeumen (Inria & Univ. Douala)

Modular Design of DSLs ICTAC 2018, Stellenbosch 10 / 16

slide-11
SLIDE 11

Algebras and modular decomposition

Polynomial and regular functors

Any locally continuous functor F : |C|p+n → |C|n has a (locally continuous) parametric fixed-point F † : |C|p → |C|n which can be computed by elimination (Beki´ c’s Theorem). Regular functors Least class of functors containing the polynomial functors and closed by type functor. Regular (and thus polynomial) functors are locally continuous.

  • E. Badouel, R. Djeumen (Inria & Univ. Douala)

Modular Design of DSLs ICTAC 2018, Stellenbosch 11 / 16

slide-12
SLIDE 12

Algebras and modular decomposition

Module

Module: G = (F, D) polynomial functor F : Cp+n+m → Cn associated with a signature Σ = (S, Ω) where S = Sp ⊎ Sd ⊎ Si with

s ∈ Sp is a parameter (|Sp| = p). s ∈ Sd is a defined sort (|Sd| = n). s ∈ Si is a imported sort (|Si| = m).

Regular functor D : Cp+n → Cm represents the imported definitions of the grammar. The functor associated with the modular grammar is the (regular) functor FG = F ◦ idp+n, D : Cp+n → Cn We let F(G) = F and D(G) = D denote the respective components of module G.

  • E. Badouel, R. Djeumen (Inria & Univ. Douala)

Modular Design of DSLs ICTAC 2018, Stellenbosch 12 / 16

slide-13
SLIDE 13

Algebras and modular decomposition

Modular Decomposition

F : Cp+n → Cn where n = n1 + n2 Subsystem: F2 = π(n1,n2)

2

  • F : Cp+n → Cn2,

Residual system: F/F2 = F1 ◦

  • idp+n1, F †

2

  • : Cp+n1 → Cn1

Beki´ c’s Theorem: F † = (F/F2)† ⋊ F †

2

The semidirect product (or cascaded composition) of functors H : Cp → Cn and T : Cp+n → Cm is given by H ⋊ T = H, T ◦ idp, H : Cp → Cn+m

  • E. Badouel, R. Djeumen (Inria & Univ. Douala)

Modular Design of DSLs ICTAC 2018, Stellenbosch 13 / 16

slide-14
SLIDE 14

Algebras and modular decomposition

Splitting of a modular Language

Proposition Let G = (F, D) be a modular grammar with polynomial functor F : Cp+n+m → Cn and regular functor D : Cp+n → Cm. If n = n1 + n2 then π(n1,n2)

2

  • FG = FG2 and

FG/G2 = FG/FG2 where the second projection G2 = π(n1,n2)

2

(G) of modular grammar G is given by F(G2) = π(n1,n2)

2

  • F(G)

: C(p+n1)+n2+m → Cn2 D(G2) = D(G) : C(p+n1)+n2 → Cm and the residual operation is defined as F(G/G2) = π(n1,n2)

1

  • F(G)

: Cp+n1+(n2+m) → Cn1 D(G/G2) = F †

G2 ⋊ D(G)

: Cp+n1 → Cn2+m Corollary: F †

G =

  • F †

G/G2

  • ⋊ F †

G2

  • E. Badouel, R. Djeumen (Inria & Univ. Douala)

Modular Design of DSLs ICTAC 2018, Stellenbosch 14 / 16

slide-15
SLIDE 15

Algebras and modular decomposition

Splitting of Catamorphisms

Decomposition of algebras F = Cp+n → Cn with n = n1 + n2. ϕ : Fζα → α with α = α1 × α2 ∈ |C|n. subalgebra: ϕ2 : F2ζα2 → α2. residual algebra: ϕ/ϕ2 ϕ1 ◦

  • F1 ζ α1 (

|ϕ2| )F2,ζ×α1

  • : (F/F2)ζα1 → α1

Theorem ( [ϕ] )F,ζ = ( [ϕ/ϕ2] )F/F2,ζ ⋊ ( [ϕ2] )F2,ζ×α1 where f ⋊ g f × (g ◦ Tζf ) : (H ⋊ T) ζ → α × β when H : Cp → Cn T : Cp+n → Cm f : Hζ → α g : Tζα → β

  • E. Badouel, R. Djeumen (Inria & Univ. Douala)

Modular Design of DSLs ICTAC 2018, Stellenbosch 15 / 16

slide-16
SLIDE 16

Conclusion

Conclusion

Growing a DSL (expression problem) versus reusing a DSL. Combine with other forms of modularity in AG: composition by aspects, descriptionnal composition, Higher-order AG ... Taking side effects into account (monadic computations). Designing and composing the roles played by participants in a collaborative system (Guarded Attribute Grammars).

  • E. Badouel, R. Djeumen (Inria & Univ. Douala)

Modular Design of DSLs ICTAC 2018, Stellenbosch 16 / 16