Duce: un aper cu Alain Frisch INRIA Rocquencourt 15 octobre 2004 - - PowerPoint PPT Presentation

duce un aper cu
SMART_READER_LITE
LIVE PREVIEW

Duce: un aper cu Alain Frisch INRIA Rocquencourt 15 octobre 2004 - - PowerPoint PPT Presentation

Duce: un aper cu Alain Frisch INRIA Rocquencourt 15 octobre 2004 GT Cristal Duce: un aper Alain Frisch cu Aper cu du langage XML Duce Fondements th eoriques Perspectives Interface avec OCaml Aper cu du langage


slide-1
SLIDE 1

❈Duce: un aper¸ cu

Alain Frisch

INRIA Rocquencourt

15 octobre 2004 GT Cristal

Alain Frisch ❈Duce: un aper¸ cu

slide-2
SLIDE 2

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

1

Aper¸ cu du langage XML ❈Duce Interface avec OCaml

2

Fondements th´ eoriques Types, mod` eles, sous-typage Calcul, typage Aspects algorithmiques

3

Perspectives

Alain Frisch ❈Duce: un aper¸ cu

slide-3
SLIDE 3

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

XML

XML dans la Vraie Vie ➋ Documents, bureautique, web. Format d’´ echange entre applications. Web-services. Stockage, bases de donn´ ees. Fichiers de configuration, XUL, . . . Comment accompagner XML ? Point du vue des langages de programmation...

Alain Frisch ❈Duce: un aper¸ cu

slide-4
SLIDE 4

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Int´ egrer donn´ ees et applications: ¸ ca ne va pas de soi ! BD relationnelles Mod` ele de donn´ ees assez simple. Langage SQL: faiblement typ´ e. Int´ egration pauvre dans langages de programmation. (corollaires en terme de sˆ uret´ e, s´ ecurit´ e, . . . ) BD objets . . .

Alain Frisch ❈Duce: un aper¸ cu

slide-5
SLIDE 5

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Sp´ ecificit´ es de XML

Notion de typage bien pr´ esente: DTD, XML Schema. Couplage « lˆ ache » entre documents et types. Les documents sont plus importants que les types ! Poids du pass´ e, choix techniques douteux. Le contenu d’un document est une notion mal d´ efinie :-(

Alain Frisch ❈Duce: un aper¸ cu

slide-6
SLIDE 6

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

« The essence of XML: The problem it solves is not hard. It doesn’t solve it very well. »

  • P. Wadler (The Essence of XML - POPL 2003)

Alain Frisch ❈Duce: un aper¸ cu

slide-7
SLIDE 7

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

D´ evelopper avec XML

Niveau 0: repr´ esentation textuelle des documents XML AWK, sed, Perl Niveau 1: vue abstraite SAX, DOM Niveau 2: petits langages sp´ ecifiques pour XML, sans types XSLT, XPath Niveau 3: types XML pris avec s´ erieux Data-binding Nouveaux langages: XQuery, XDuce, CDuce, Xtatic, Xen.

Alain Frisch ❈Duce: un aper¸ cu

slide-8
SLIDE 8

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Data-binding

Principe Utiliser les types d’un langage hˆ

  • te pour repr´

esenter les types XML. Avantage On reste dans le cadre d’un langage bien maˆ ıtris´ e. Probl` emes On perd la souplesse des types XML (expressions r´ eguli` eres). On se repose sur un syst` eme de types trop grossier. Probl` eme de robustesse: ´ evolution des sch´ emas XML. Impedance mismatch entre mod` ele XML et mod` ele OO.

Alain Frisch ❈Duce: un aper¸ cu

slide-9
SLIDE 9

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

CDuce

Langage:

  • rient´

e XML ; centr´ e sur les types ; avec des caract´ eristiques g´ en´ eralistes ; (vaguement) efficace.

Alain Frisch ❈Duce: un aper¸ cu

slide-10
SLIDE 10

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

CDuce

Outil d’exp´ erimentation (valider la th´ eorie, essayer algorithmes, optimisations, . . . ). N´ eanmoins ` a peu pr` es utilisable (et utilis´ e). Sc´ enarios d’utilisation Petits “adaptateurs” entre applications XML. Applications plus grosses. Applications web, web services. Couche d’E/S XML pour des applications OCaml.

Alain Frisch ❈Duce: un aper¸ cu

slide-11
SLIDE 11

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Orient´ e XML, centr´ e sur les donn´ ees

Litteraux XML dans la syntaxe. Fragments XML: citoyens de premi` ere classe, pas enfouis dans des objets.

<program>[ <date day="monday">[ <invited>[ <title>[ ’Conservation of information’ ] <author>[ ’Thomas Knight, Jr.’ ] ] <talk>[ <title>[ ’Scripting the type-inference process’ ] <author>[ ’Bastiaan Heeren’ ] <author>[ ’Jurriaan Hage’ ] <author>[ ’Doaitse Swierstra’ ] ] ] ] Alain Frisch ❈Duce: un aper¸ cu

slide-12
SLIDE 12

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Types

Les types sont partout dans CDuce: Validation statique

Ex.: est-ce que ¸ ca produit toujours du XHTML valide ?

Semantique dirig´ ee par les types

Dispatch dynamique Fonctions surcharg´ ees

Compilation dirig´ ee par les types

Optimisations rendues possibles par les types statiques ´ Evite des op´ erations inutiles/redondantes ` a l’ex´ ecution Autorise un style plus d´ eclaratif

Alain Frisch ❈Duce: un aper¸ cu

slide-13
SLIDE 13

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

XML avec des types

⊢ v : t

v == <program>[ <date day="monday">[ <invited>[ <title>[ ’Conservation of information’ ] <author>[ ’Thomas Knight, Jr.’ ] ] <talk>[ <title>[ ’Scripting the type-inference process’ ] <author>[ ’Bastiaan Heeren’ ] <author>[ ’Jurriaan Hage’ ] <author>[ ’Doaitse Swierstra’ ] ] ] ] t == <program>[ <date day="monday">[ <invited>[ <title>[ ’Conservation of information’ ] <author>[ ’Thomas Knight, Jr.’ ] ] <talk>[ <title>[ ’Scripting the type-inference process’ ] <author>[ ’Bastiaan Heeren’ ] <author>[ ’Jurriaan Hage’ ] <author>[ ’Doaitse Swierstra’ ] ] ] ] Alain Frisch ❈Duce: un aper¸ cu

slide-14
SLIDE 14

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

XML avec des types

⊢ v : t

v == <program>[ <date day="monday">[ <invited>[ <title>[ ’Conservation of information’ ] <author>[ ’Thomas Knight, Jr.’ ] ] <talk>[ <title>[ ’Scripting the type-inference process’ ] <author>[ ’Bastiaan Heeren’ ] <author>[ ’Jurriaan Hage’ ] <author>[ ’Doaitse Swierstra’ ] ] ] ] t == <program>[ <date day=String>[ <invited>[ <title>[ PCDATA ] <author>[ PCDATA ] ] <talk>[ <title>[ PCDATA ] <author>[ PCDATA ] <author>[ PCDATA ] <author>[ PCDATA ] ] ] ] Alain Frisch ❈Duce: un aper¸ cu

slide-15
SLIDE 15

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

XML avec des types

⊢ v : t

v == <program>[ <date day="monday">[ <invited>[ <title>[ ’Conservation of information’ ] <author>[ ’Thomas Knight, Jr.’ ] ] <talk>[ <title>[ ’Scripting the type-inference process’ ] <author>[ ’Bastiaan Heeren’ ] <author>[ ’Jurriaan Hage’ ] <author>[ ’Doaitse Swierstra’ ] ] ] ] t == <program>[ <date day=String>[ <invited>[ Title Author ] <talk>[ Title Author Author Author ] ] ] type Author = <author>[ PCDATA ] type Title = <title>[ PCDATA ] Alain Frisch ❈Duce: un aper¸ cu

slide-16
SLIDE 16

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

XML avec des types

⊢ v : t

v == <program>[ <date day="monday">[ <invited>[ <title>[ ’Conservation of information’ ] <author>[ ’Thomas Knight, Jr.’ ] ] <talk>[ <title>[ ’Scripting the type-inference process’ ] <author>[ ’Bastiaan Heeren’ ] <author>[ ’Jurriaan Hage’ ] <author>[ ’Doaitse Swierstra’ ] ] ] ] t == <program>[ <date day=String>[ <invited>[ Title Author+ ] <talk>[ Title Author+ ] ] ] type Author = <author>[ PCDATA ] type Title = <title>[ PCDATA ] Alain Frisch ❈Duce: un aper¸ cu

slide-17
SLIDE 17

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

XML avec des types

⊢ v : t

v == <program>[ <date day="monday">[ <invited>[ <title>[ ’Conservation of information’ ] <author>[ ’Thomas Knight, Jr.’ ] ] <talk>[ <title>[ ’Scripting the type-inference process’ ] <author>[ ’Bastiaan Heeren’ ] <author>[ ’Jurriaan Hage’ ] <author>[ ’Doaitse Swierstra’ ] ] ] ] t == Program type Program = <program>[ Day* ] type Day = <date day=String>[ Invited? Talk+ ] type Invited = <invited>[ Title Author+ ] type Talk = <talk>[ Title Author+ ] type Author = <author>[ PCDATA ] type Title = <title>[ PCDATA ] Alain Frisch ❈Duce: un aper¸ cu

slide-18
SLIDE 18

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Filtrage

Op´ eration de base du langage. Le syst` eme de type garantit l’exhaustivit´ e et inf` ere le type (exact) des variables de capture. D´ etection des branches/motifs inutilis´ es.

Alain Frisch ❈Duce: un aper¸ cu

slide-19
SLIDE 19

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Filtrage: un petit goˆ ut de ML

match e with <date day=d>_ -> d type E = <add>[Int Int] | <sub>[Int Int] fun eval (E -> Int) | <add>[ x y ] -> x + y | <sub>[ x y ] -> x - y

Les motifs sont des “types avec des variables de capture”.

Alain Frisch ❈Duce: un aper¸ cu

slide-20
SLIDE 20

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Filtrage: au del` a de ML

Dispatch sur le type:

match e with | x & Int -> ... | x & Char -> ... let doc = match (load_xml "doc.xml") with | x & DocType -> x | _ -> raise "Invalid input !";; Alain Frisch ❈Duce: un aper¸ cu

slide-21
SLIDE 21

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Filtrage: au del` a de ML

Expressions r´ eguli` eres et capture:

fun (Invited|Talk -> [Author+]) <_>[ Title x::Author* ] -> x fun ([(Invited|Talk|Event)*] -> ([Invited*], [Talk*])) [ (i::Invited | t::Talk | _)* ] -> (i,t) fun parse_email (String -> (String,String)) | [ local::_* ’@’ domain::_* ] -> (local,domain) | _ -> raise "Invalid email address" Alain Frisch ❈Duce: un aper¸ cu

slide-22
SLIDE 22

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Fonctions

Surcharg´ ees, de premi` ere classe, sous-typage, partage de nom, partage de code . . .

type Program = <program>[ Day* ] type Day = <date day=String>[ Invited? Talk+ ] type Invited = <invited>[ Title Author+ ] type Talk = <talk>[ Title Author+ ] let patch_program (p:[Program], f:(Invited -> Invited) & (Talk -> Talk)):[Program] = xtransform p with (Invited | Talk) & x -> [ (f x) ] let first_author ([Program] -> [Program]; Invited -> Invited; Talk -> Talk) | [ Program ] & p -> patch_program (p,first_author) | <invited>[ t a _* ] -> <invited>[ t a ] | <talk>[ t a _* ] -> <talk>[ t a ] (* On peut remplacer les deux derni` eres branches par: <(k)>[ t a _* ] -> <(k)>[ t a ] *) Alain Frisch ❈Duce: un aper¸ cu

slide-23
SLIDE 23

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Un autre exemple

type Person = FPerson | MPerson type FPerson = <person gender="F">[ Name Children ] type MPerson = <person gender="M">[ Name Children ] type Children = <children>[Person*] type Name = <name>[ PCDATA ] type Man = <man name=String>[ Sons Daughters ] type Woman = <woman name=String>[ Sons Daughters ] type Sons = <sons>[ Man* ] type Daughters = <daughters>[ Woman* ] let split (MPerson -> Man ; FPerson -> Woman) <person gender=g>[ <name>n <children>[(mc::MPerson | fc::FPerson)*] ] -> let tag = match g with "F" -> ‘woman | "M" -> ‘man in let s = map mc with x -> split x in let d = map fc with x -> split x in <(tag) name=n>[ <sons>s <daughters>d ] Alain Frisch ❈Duce: un aper¸ cu

slide-24
SLIDE 24

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Expressivit´ e du filtrage

... <person gender=g>[...] -> let tag = match g with "F" -> ‘woman | "M" -> ‘man in ...

peut ˆ etre remplac´ e par:

<person gender=("F" & (tag := ‘woman) | (tag := ‘man))>[...] ->

  • u par:

<person>[...] & (FPerson & (tag := ‘woman) | MPerson & (tag := ‘man)) ->

(Plus robuste aux changements de repr´ esentation !)

Alain Frisch ❈Duce: un aper¸ cu

slide-25
SLIDE 25

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Erreurs de types pr´ ecises

type Title = <title>String type Author = <author>String type Talk = <talk>[ Title Author+ ] let x : Talk = <talk>[ <author>[ ’Alain Frisch’ ] <title>[ ’CDuce’ ] ] ❀ let x : Talk = <talk>[ <author>[ ’Alain Frisch’ ] <title>[ ’CDuce’ ] ] let x : Talk = <talk>[ <author>[ ’Alain Frisch’ ] <title>[ ’CDuce’ ] ] let x : Talk = <talk>[ <author>[ ’Alain Frisch’ ] <title>[ ’CDuce’ ] ] This expression should have type: ‘title but its inferred type is: ‘author which is not a subtype, as shown by the sample: ‘author Alain Frisch ❈Duce: un aper¸ cu

slide-26
SLIDE 26

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Erreurs de types pr´ ecises

type Title = <title>String type Author = <author>String type Talk = <talk>[ Title Author+ ] fun mk_talk(s : String) : Talk = <talk>[ <title>s ] ❀ fun mk_talk(s : String) : Talk = <talk>[ <title>s ] fun mk_talk(s : String) : Talk = <talk>[ <title>s ] fun mk_talk(s : String) : Talk = <talk>[ <title>s ] This expression should have type: [ Author+ ] but its inferred type is: [ ] which is not a subtype, as shown by the sample: [ ] Alain Frisch ❈Duce: un aper¸ cu

slide-27
SLIDE 27

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Erreurs de types pr´ ecises

type Title = <title>String type Author = <author>String type Talk = <talk>[ Title Author+ ] type Invited = <invited>[ Title Author+ ] type Day = <date>[ Invited? Talk+ ] fun (Day -> [Talk+]) <date>[ Invited? x::_*] -> x fun (Day -> [Talk+]) <date>[ _? x::_*] -> x ❀ fun (Day -> [Talk+]) <date>[ _? x::_*] -> x fun (Day -> [Talk+]) <date>[ _? x::_*] -> x fun (Day -> [Talk+]) <date>[ _? x::_*] -> x This expression should have type: [ Talk+ ] but its inferred type is: [ Talk* ] which is not a subtype, as shown by the sample: [ ] Alain Frisch ❈Duce: un aper¸ cu

slide-28
SLIDE 28

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Erreurs de types pr´ ecises

type Program = <program>[ Day* ] type Day = <date day=String>[ Invited? Talk+ ] type Invited = <invited>[ Title Author+ ] type Talk = <talk>[ Title Author+ ] type Author = <author>[ PCDATA ] type Title = <title>[ PCDATA ] fun (p :[Program]):[Program] = xtransform p with Invited -> [] fun (p :[Program]):[Program] = xtransform p with <invited>c -> [<talk>c] fun (p :[Program]):[Program] = xtransform p with Talk -> [] ❀ fun (p :[Program]):[Program] = xtransform p with Talk -> [] fun (p :[Program]):[Program] = xtransform p with Talk -> [] fun (p :[Program]):[Program] = xtransform p with Talk -> [] This expression should have type: [ Program ] but its inferred type is: [ <program>[ <date day = String>[ Invited? ]* ] ] which is not a subtype, as shown by the sample: [ <program>[ <date day = "">[ ] ] ] Alain Frisch ❈Duce: un aper¸ cu

slide-29
SLIDE 29

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Interface avec OCaml

Appeler OCaml depuis CDuce R´ eutiliser biblioth` eques (y compris bindings avec C). Structures de donn´ ees et algorithmes complexes. Passer fonctions CDuce comme arguments. Instancier fonctions polymorphes avec types CDuce. Utiliser une unit´ e CDuce comme un module OCaml ❈Duce comme couche E/S pour applis OCaml. Pr´ esentation XHTML de r´ esultats, CGI, s´ erialisation des donn´ ees internes, gestion des fichiers de config.

Alain Frisch ❈Duce: un aper¸ cu

slide-30
SLIDE 30

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Interface avec OCaml

Objectifs On veut: Pr´ eserver sˆ uret´ e du typage. ´ Eviter d’´ ecrire fonctions de coercions. Approche retenue Une fonction de traduction dans un seul sens: OCaml = ⇒ CDuce. Pour un type OCaml t, d´ eduire un type CDuce ˆ t et deux fonctions de coercion t ↔ ˆ t. Un mapping CDuce = ⇒ OCaml ne peut pas ˆ etre compatible avec le sous-typage (sauf un mapping constant) !

Alain Frisch ❈Duce: un aper¸ cu

slide-31
SLIDE 31

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Traduction des types

t ˆ t int min int − −max int string Latin1 t1 ∗ t2 (ˆ t1, ˆ t2) t1 → t2 ˆ t1 → ˆ t2 A1 of t1 | . . . | An of tn (‘A1, ˆ t1) | . . . | (‘An, ˆ tn) [‘A1 of t1 | . . . | ‘An of tn] (‘A1, ˆ t1) | . . . | (‘An, ˆ tn) {l1 = t1; . . . ; ln = tn} {|l1 = ˆ t1; . . . ; ln = ˆ tn|} t list [ˆ t∗] t ref {|get = [] → ˆ t; set = ˆ t → []|} t (abstrait) !t CDuce.Value.t Any Big int.big int Int

Alain Frisch ❈Duce: un aper¸ cu

slide-32
SLIDE 32

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Appeler OCaml depuis CDuce

Soit v une valeur OCaml de type t. Pour l’utiliser depuis CDuce: appliquer la coercion t → ˆ t.

let home = Sys.getenv "HOME" (* Latin1 *) let exists = Sys.file exists (* Latin1 -> Bool *) let listmap = List.map { Int Int } (* (Int -> Int) -> [Int*] -> [Int*] *) let lst = listmap (fun (x : Int) : Int = x * 2) [ 10 20 30 ] (* [Int*] *)

Caract´ eristiques OCaml non g´ er´ ees Objets (faisable) Tableaux (facile) Types r´ ecursifs non r´ eguliers (impossible) Types abstraits param´ etr´ es (faisable)

Alain Frisch ❈Duce: un aper¸ cu

slide-33
SLIDE 33

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Appeler OCaml depuis CDuce

L’instanciation des variables de type OCaml par des types ❈Duce est-elle sˆ ure ? Oui ! Si f : ∀α.τ[α], alors f : τ[X] pour n’importe quel ensemble X de valeurs.

Alain Frisch ❈Duce: un aper¸ cu

slide-34
SLIDE 34

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Appeler CDuce depuis OCaml

CDuce produit des unit´ es de compilation OCaml (l’interface .cmi est donn´ ee par le programmeur).

  • camlc -c a.mli

❀ a.cmi cduce --compile a.cd ❀ a.cdo

  • camlc -c -impl a.cdo -pp cdo2ml

❀ a.cmo

  • camlc -o prog ... a.cmo ...

❀ prog a.cd a.mli

let aux ((Int,Int) -> Int) | (x, 0 | 1) -> x | (x, n) -> aux (x * n, n - 1) let fact (x : Int) : Int = aux (1, x) val fact: Big int.big int -> Big int.big int Alain Frisch ❈Duce: un aper¸ cu

slide-35
SLIDE 35

Aper¸ cu du langage Fondements th´ eoriques Perspectives XML ❈Duce Interface avec OCaml

Autres caract´ eristiques

G´ en´ eralistes: enregistrements, tuples, entiers, exceptions, r´ ef´ erences, . . . Chaˆ ınes + expressions r´ eguli` eres (types, motifs) Connecteurs bool´ eens (types, motifs) Autres it´ erateurs Fragment de XPath, select..from..where...

Alain Frisch ❈Duce: un aper¸ cu

slide-36
SLIDE 36

Aper¸ cu du langage Fondements th´ eoriques Perspectives Types, mod` eles, sous-typage Calcul, typage Aspects algorithmiques

1

Aper¸ cu du langage XML ❈Duce Interface avec OCaml

2

Fondements th´ eoriques Types, mod` eles, sous-typage Calcul, typage Aspects algorithmiques

3

Perspectives

Alain Frisch ❈Duce: un aper¸ cu

slide-37
SLIDE 37

Aper¸ cu du langage Fondements th´ eoriques Perspectives Types, mod` eles, sous-typage Calcul, typage Aspects algorithmiques

Alg` ebres de termes cycliques

Les types et les motifs sont des objets cycliques (graphes/automates) sans lieur. On veut pouvoir les manipuler comme des termes (constructeurs/destructeurs) d’une alg` ebre, et laisser les questions de partage et de repr´ esentation ` a l’impl´ ementation. On veut faire passer de la th´ eorie des automates pour de la th´ eorie des types ! Petit cadre cat´ egorique pour faire ¸ ca proprement.

Alain Frisch ❈Duce: un aper¸ cu

slide-38
SLIDE 38

Aper¸ cu du langage Fondements th´ eoriques Perspectives Types, mod` eles, sous-typage Calcul, typage Aspects algorithmiques

Alg` ebres de termes cycliques

Soit F : Set → Set un foncteur « signature ». Une F-coalg` ebre est un couple (T, τ) avec T ensemble, τ : T → FT. Coalg` ebre r´ eguli` ere: tout ´ el´ ement de T est dans une sous-coal` ebre finie.

⇒ terminaison des algorithmes.

Coalg` ebre r´ ecursive: toute extension finie se retracte (par un morphisme) dans T.

⇒ existence de types r´ ecursifs introduits par des syst` emes d’´ equations.

Remarque: pas de propri´ et´ e universelle (pas d’unicit´ e des solutions ⇒ libert´ e laiss´ e ` a l’impl´ ementation pour avoir plus

  • u moins de partage).

Constructions: partage optimal, partage minimal, partage modulo renommage des lieurs.

Alain Frisch ❈Duce: un aper¸ cu

slide-39
SLIDE 39

Aper¸ cu du langage Fondements th´ eoriques Perspectives Types, mod` eles, sous-typage Calcul, typage Aspects algorithmiques

Types

Foncteur: F = B ◦ S a ∈ SX := b type de base | x× × ×x constructeur produit | x→ → →x constructeur fl` eche | . . . (XML, enregistrements) t ∈ BA := a atome | t∨ ∨ ∨t | t∧ ∧ ∧t | ¬ ¬ ¬t connecteurs bool´ eens | ✵ | ✶ types vide, plein Garantit bonne formation de la r´ ecursion (exclure µα. α∨ ∨ ∨α). En fait, ´ egalit´ e modulo tautologies bool´ eennes pour B ; par exemple, formes normales disjonctives: BA = Pf (Pf (A) × Pf (A))

Alain Frisch ❈Duce: un aper¸ cu

slide-40
SLIDE 40

Aper¸ cu du langage Fondements th´ eoriques Perspectives Types, mod` eles, sous-typage Calcul, typage Aspects algorithmiques

Types

Les types d´ ecrivent des ensembles de valeurs. Sous-typage s´ emantique (ensembliste): t ≤ s ⇐ ⇒ t ⊆ s

  • `

u t = {v | ⊢ v : t} Probl` eme: d´ efinition circulaire entre sous-typage et typage! Le sous-typage d´ epend du typage des valeurs. Le typage des valeurs d´ epend du typage des expressions (λ-abstractions !). Le typage des expressions d´ epend du sous-typage (r` egle de subsomption !). ❀ d´ eveloppement d’une m´ ethode d’amor¸ cage

Alain Frisch ❈Duce: un aper¸ cu

slide-41
SLIDE 41

Aper¸ cu du langage Fondements th´ eoriques Perspectives Types, mod` eles, sous-typage Calcul, typage Aspects algorithmiques

Amor¸ cage

On consid` ere des interpr´ etations bool´ eennes de l’alg` ebre de types : T → P(D) (t1∨ ∨ ∨t2 = t1 ∪ t2, . . . ). Soit une telle interpr´

  • etation. On pose:

❊D = C + D × D + DD ❊ : T → P(❊D) ❊t1× × ×t2 = t1 × t2 ❊t1→ → →t2 = {f : D → D | f (t1) ⊆ t2} « Moralement » on veut D = ❊D. C’est impossible ! On dit que est un mod` ele si: ∀t. t = ∅ ⇐ ⇒ ❊t = ∅

  • u encore:

∀t, s. t ⊆ s ⇐ ⇒ ❊t ⊆ ❊s

Alain Frisch ❈Duce: un aper¸ cu

slide-42
SLIDE 42

Aper¸ cu du langage Fondements th´ eoriques Perspectives Types, mod` eles, sous-typage Calcul, typage Aspects algorithmiques

Amor¸ cage

Chaque mod` ele induit une relation de sous-typage: t ≤ s ⇐ ⇒ t ⊆ s. Toute la th´ eorie qui suit ne d´ epend pas du choix du mod` ele d’amorce. On peut construire un mod` ele universel (qui induit la plus grande relation ≤), des mod` eles non universels (pas facile !).

Alain Frisch ❈Duce: un aper¸ cu

slide-43
SLIDE 43

Aper¸ cu du langage Fondements th´ eoriques Perspectives Types, mod` eles, sous-typage Calcul, typage Aspects algorithmiques

Raisonnements dans les mod` eles

Propri´ et´ es simples: transitivit´ e de ≤, variance des constructeurs, tautologies bool´ eennes, ´ egalit´ es ensemblistes (t1× × ×s1)∧ ∧ ∧(t2× × ×s2) ≃ (t1∧ ∧ ∧t2)× × ×(s1∧ ∧ ∧s2). Tr` es utile pour pr´ eparer l’´ etude algorithmique du sous-typage et pour mener l’´ etude m´ eta-th´ eorique du syst` eme de types !

Alain Frisch ❈Duce: un aper¸ cu

slide-44
SLIDE 44

Aper¸ cu du langage Fondements th´ eoriques Perspectives Types, mod` eles, sous-typage Calcul, typage Aspects algorithmiques

R` egles de sous-typage

  • i∈I

ti× × ×si ≤

  • i∈J

ti× × ×si ⇐ ⇒ ∀J′ ⊆ J.

  • i∈I

ti ≤

  • i∈J′

ti

  • u

 

  • i∈I

si ≤

  • i∈J\J′

si  

  • i∈I

ti→ → →si ≤

  • i∈J

ti→ → →si ⇐ ⇒ ∃j ∈ J.∀I ′ ⊆ I.

  • tj ≤
  • i∈I ′

ti

  • u

 I ′ = I et

  • i∈I\I ′

si ≤ sj  

Alain Frisch ❈Duce: un aper¸ cu

slide-45
SLIDE 45

Aper¸ cu du langage Fondements th´ eoriques Perspectives Types, mod` eles, sous-typage Calcul, typage Aspects algorithmiques

Typage de l’application fonctionnelle

Exemple avanc´ e de raisonnement ensembliste. app : ((t→ → →s)× × ×t)→ → →s (app→ → →) app : t1→ → →s1 app : t2→ → →s2 app : (t1∧ ∧ ∧t2)→ → →(s1∧ ∧ ∧s2) (app∧ ∧ ∧) app : t1→ → →s1 app : t2→ → →s2 app : (t1∨ ∨ ∨t2)→ → →(s1∨ ∨ ∨s2) (app∨ ∨ ∨) app : t′→ → →s′ t ≤ t′ s′ ≤ s app : t→ → →s (app ≤) Thm: si t ≃

  • i=1..n

ti

× ×ti

2, alors: (app : t→

→ →s) ⇐ ⇒ ∀i. ti

1 ≤ ti 2→

→ →s M´ ethode: passer par une interpr´ etation ensembliste de l’application dans un mod` ele D′ d´ eduit de D ; app(t′) ⊆ s′.

Alain Frisch ❈Duce: un aper¸ cu

slide-46
SLIDE 46

Aper¸ cu du langage Fondements th´ eoriques Perspectives Types, mod` eles, sous-typage Calcul, typage Aspects algorithmiques

Calcul, syst` eme de types

Γ ⊢ c : bc Γ ⊢ x : Γ(x) Γ ⊢ e : t

  • : t→

→ →s Γ ⊢ o(e) : s Γ ⊢ e : t1 t1 ≤ t2 Γ ⊢ e : t2 Γ ⊢ e1 : t1 Γ ⊢ e2 : t2 Γ ⊢ (e1, e2) : t1× × ×t2

Alain Frisch ❈Duce: un aper¸ cu

slide-47
SLIDE 47

Aper¸ cu du langage Fondements th´ eoriques Perspectives Types, mod` eles, sous-typage Calcul, typage Aspects algorithmiques

Calcul, syst` eme de types

t =

  • i=1..n

(ti→ → →si)∧ ∧ ∧

  • j=1..m

¬ ¬ ¬(t′

j→

→ →s′

j) ≃ ✵

∀i = 1..n. (f : t), (x : ti), Γ ⊢ e : si Γ ⊢ µf (t1→ → →s1; . . . ; tn→ → →sn).λx.e : t Γ ⊢ e : t0 ≤ p1 ∨ ∨ ∨ p2 ((t0∧ ∧ ∧ p1)/ / /p1), Γ ⊢ e1 : s1 ((t0\ \ \ p2)/ / /p2), Γ ⊢ e2 : s2 Γ ⊢ match e with p1 → e1 | p2 → e2 : s1∨ ∨ ∨s2 (p, (t/ / /p) sont d´ efinis de mani` ere s´ emantique)

Alain Frisch ❈Duce: un aper¸ cu

slide-48
SLIDE 48

Aper¸ cu du langage Fondements th´ eoriques Perspectives Types, mod` eles, sous-typage Calcul, typage Aspects algorithmiques

R´ esultats

On obtient un mod` ele en prenant tV = {v | ⊢ v : t}. Il est ´ equivalent au mod` ele d’amorce ! Sˆ uret´ e pour une s´ emantique ` a petits pas. Pas de type « principal », mais l’ensemble des types d’une expression est un filtre ; algorithme d’inf´ erence. Impl´ ementation de l’algorithme de typage avec propagation bidirectionnelle des contraintes pour localiser erreurs. Exactitude du typage de l’application: app : t→ → →s ⇐ ⇒ ∀v ∈ tV.app(v) ∗ ❀ v′ ⇒ v′ ∈ sV

Alain Frisch ❈Duce: un aper¸ cu

slide-49
SLIDE 49

Aper¸ cu du langage Fondements th´ eoriques Perspectives Types, mod` eles, sous-typage Calcul, typage Aspects algorithmiques

Calcul du sous-typage

Pour un mod` ele universel, le pr´ edicat unaire P(t) ≡ t = ∅ est un pr´ edicat inductif (mais pas sur la structure de t qui est cyclique !). Modularisation de l’algorithme de sous-typage. Utiliser des raisonnements s´ emantiques pour d´ eduire une d´ efinition de P comme solution minimale d’un syst` eme de contraintes bool´ eennes {Φ(t) ⇒ P(t) | t ∈ T} o` u Φ(t) est une formule bool´ eenne positive construite sur des P(t′).

Plusieurs versions possibles. Heuristiques pour traiter cas usuels.

Utiliser un solveur l´ eger de contraintes bool´ eennes.

Alain Frisch ❈Duce: un aper¸ cu

slide-50
SLIDE 50

Aper¸ cu du langage Fondements th´ eoriques Perspectives Types, mod` eles, sous-typage Calcul, typage Aspects algorithmiques

Solveur avec backtracking

eval(t, N, P) := if t ∈ P then (1, N, P) else if t ∈ N then (0, N, P) else match eval(Φ(t), N ∪ {t}, P) with | (0, N′, P′) → (0, N′, P′) | (1, N′, P′) → (1, N, P′ ∪ {t}) eval(φ1 ∧ φ2, N, P) := match eval(φ1, N, P) with | (0, N′, P′) → (0, N′, P′) | (1, N′, P′) → eval(φ2, N′, P′) eval(φ1 ∨ φ2, N, P) := match eval(φ1, N, P) with | (0, N′, P′) → eval(φ2, N′, P′) | (1, N′, P′) → (1, N′, P′) eval(0, N, P) := (0, N, P) eval(1, N, P) := (1, N, P)

On peut impl´ ementer N et P avec une structure persistente (table de hash) + une pile pour backtracker N !

Alain Frisch ❈Duce: un aper¸ cu

slide-51
SLIDE 51

Aper¸ cu du langage Fondements th´ eoriques Perspectives Types, mod` eles, sous-typage Calcul, typage Aspects algorithmiques

Solveur sans backtracking

Id´ ees: Garder les d´ ependences entre assertions en cours de v´ erification et leurs cons´ equences. Retarder autant que possible le d´ eroulement des formules bool´ eennes. Utiliser la structure du treillis {0, 1} (hauteur 2) pour simplifier !

Alain Frisch ❈Duce: un aper¸ cu

slide-52
SLIDE 52

Aper¸ cu du langage Fondements th´ eoriques Perspectives Types, mod` eles, sous-typage Calcul, typage Aspects algorithmiques

Compilation du filtrage

Implementation du filtrage ❀ Sans backtracking ❀ Utilise les informations de types statiques ❀ Factorisation des captures ❀ Autorise un style plus d´ eclaratif (❀ robuste)

type A = <a>[ Int* ] type B = <b>[ Char* ] fun ([A+|B+] -> Int) [A+] -> 0 | [B+] -> 1 ≃ fun ([A+|B+] -> Int) [ <a>_ _* ] -> 0 | _ -> 1 Alain Frisch ❈Duce: un aper¸ cu

slide-53
SLIDE 53

Aper¸ cu du langage Fondements th´ eoriques Perspectives Types, mod` eles, sous-typage Calcul, typage Aspects algorithmiques

Repr´ esentation des valeurs

Concat´ enation en temps constant (repr´ esentation symbolique), avec applatissement ` a la demande. Repr´ esentation compacte des chaˆ ınes de caract` eres. Hash-consing des tags XML.

Alain Frisch ❈Duce: un aper¸ cu

slide-54
SLIDE 54

Aper¸ cu du langage Fondements th´ eoriques Perspectives

1

Aper¸ cu du langage XML ❈Duce Interface avec OCaml

2

Fondements th´ eoriques Types, mod` eles, sous-typage Calcul, typage Aspects algorithmiques

3

Perspectives

Alain Frisch ❈Duce: un aper¸ cu

slide-55
SLIDE 55

Aper¸ cu du langage Fondements th´ eoriques Perspectives

XML

G´ erer les pointeurs dans les documents (aka ID/IDREF), et inter-documents (XLink/XPointer). Typer l’op´ eration « p` ere » (le type parle du contexte, pas seulement du sous-arbre). Int´ eractions avec le typage par nom (approche de XML Schema / XQuery / XSLT).

Alain Frisch ❈Duce: un aper¸ cu

slide-56
SLIDE 56

Aper¸ cu du langage Fondements th´ eoriques Perspectives

Compilation

Variantes d’heuristiques pour la compilation du filtrage (moins sp´ ecialiser pour avoir code plus compact). Techniques de fusing/d´ eroulement/sp´ ecialisation pour profiter autant que possible de l’impl´ ementation efficace du filtrage. R´ esolution statique de la surcharge ` a l’appel des fonctions. Repr´ esentation des valeurs.

Alain Frisch ❈Duce: un aper¸ cu

slide-57
SLIDE 57

Aper¸ cu du langage Fondements th´ eoriques Perspectives

Polymorphisme param´ etrique

On a: polymorphisme par sous-typage et par surcharge. On veut: op´ erations g´ en´ eriques. 2 pistes:

Polymorphisme param´ etrique: ajoute de variables dans l’alg` ebre de types ; quantification universelle. It´ erateurs r´ ecursifs g´ en´ eriques dont le typage est repouss´ e ` a l’application: g´ en´ eralisation des it´ erateurs pr´ ed´ efinis, du filtrage, encodage de XPath, tout ¸ ca avec un typage tr` es pr´

  • ecis. Typage = d´

erouler l’it´ erateur et le type de l’argument pour les synchroniser...

Alain Frisch ❈Duce: un aper¸ cu

slide-58
SLIDE 58

Aper¸ cu du langage Fondements th´ eoriques Perspectives

Rapprocher ❈Duce et ML

Objectif: extension conservative (ou pas) de ML avec un type XML, sous-typage s´ emantique, et filtrage XML (annotations explicites !). En fait, ´ etendre ML avec: - une alg` ebre de types externes pour laquelle on dispose de ≤ (implicite) et ∨ ∨ ∨ ; - des constructions avec typage bottom-up. Refinement types, inf´ erence locale, HM(X), . . . Pour aller plus loin: m´ elanger plus en profondeur les alg` ebres de types (variables ML dans le type XML) . . .

Alain Frisch ❈Duce: un aper¸ cu

slide-59
SLIDE 59

Aper¸ cu du langage Fondements th´ eoriques Perspectives

Travaux en cours autour de ❈Duce

Sous-typage s´ emantique des canaux du π-calcul (R. De Nicola, D. Varacca, G. Castagna) Securit´ e & analyse de flot d’information (M. Burelle, G. Castagna) Langage de requˆ ete CQL (C. Miachon, V. Benzaken) Int´ egration XPath / filtrage (K. Nguyen, G. Castagna, A. Frisch) Error mining dans ❈Duce (D. Colazzo, G. Castagna, A. Frisch) BD XML native (V. Benzaken, I. Manolescu) Polymorphisme param´ etrique (H. Hosoya, G. Castagna, A. Frisch)

Alain Frisch ❈Duce: un aper¸ cu

slide-60
SLIDE 60

Aper¸ cu du langage Fondements th´ eoriques Perspectives

Merci !

http://www.cduce.org/

Alain Frisch ❈Duce: un aper¸ cu