Langage de Programmation 2   (LP2  ) - RICM3   Cours 7   Inf  351rence  de type, Makefile, R  351f
48 pages
English

Langage de Programmation 2 (LP2 ) - RICM3 Cours 7 Inf 351rence de type, Makefile, R 351f

-

Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres
48 pages
English
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres

Description

Langage de Programmation 2 (LP2)Langage de Programmation 2 (LP2)RICM3Cours 7Inférence de type, Makefile, Référence, mutablePascal LafourcadePolytech2009 - 20101 / 56Langage de Programmation 2 (LP2)PlanTypage suiteTypage des exceptionsBilanUnificationTerms and MessagesUnificationVérification de types polymorphesSytème FSystème de Hindley-MilnerInférence de TypeConclusion2 / 56Langage de Programmation 2 (LP2)Typage suiteTypage du filtrage (match)type t = C of T ×...T |... | C of T ×...T1 1,1 1,n p p,1 p,n1 pPosons  match E with . ..M = |C (x ,...x ) → Ei 1 n ii . ..où chaque expression E dépend de x ...x .i 1 niE :t ∀i,1≤i≤p, Γ;x 7!T ...x 7!T ⊢ E :T1 p,1 n p,n ii iΓ ⊢ M :T4 / 56Langage de Programmation 2 (LP2)Typage suiteTypage du matchExemple : fact II# let rec fact n = match n with| 0 -> 1| n -> n* (fact (n-1));;val fact : int -> int = 5 / 56Langage de Programmation 2 (LP2)Typage suiteTypage des exceptionsExceptionstry E with| ListeVide→ E1| Alarme (n, b)→ E (n,b) = T (une expression)2| Not_found→ E3| Division_by_zero→ E4E, E , E (n,b), E , E , ... doivent avoir le même type,1 2 3 4qui est le type de l’expression entière T.E :t E :t E (n,b) :t E :t E :t1 2 3 4T :t6 / 566Langage de Programmation 2 (LP2)BilanRappel des règles de typageΓ ⊢ 0 : intΓ;x7!t ⊢ x :tΓ ⊢ x :t x =yΓ;y7!u ⊢ x :tΓ ⊢ B : bool Γ ⊢ E :t Γ ⊢ E :t1 2Γ ⊢ (if B then E else E ) :t1 2Γ ⊢ A :t Γ ⊢ B :uΓ ⊢ (A,B) :t×uΓ ⊢ E :T ... Γ ⊢ E ...

Informations

Publié par
Nombre de lectures 56
Langue English

Extrait

LangagedeProgrammation2L(2P)
Langage de Programmation 2 RICM3 Cours 7 Inférence de type, Makefile, Référence,
Pascal Lafourcade
Polytech
2009 - 2010
(LP2)
mutable
1 / 56
LnaagegderPgo
Plan
rammatino2(LP2)
Typage suite Typage des exceptions
Bilan
Unification Terms and Messages Unification
Vérification de types polymorphes Sytème F Système de Hindley-Milner
Inférence de Type
Conclusion
2 / 56
LnagTyapgaegdeesPuirtoergmamation2L(2P)
Typage du filtrage (match)
typet=C1ofT11×  T1n1|  |CpofTp1×  Tpnp
Posons
matchEwith M=.|Ci(x1   xni)Ei . où chaque expressionEidépend dex1  xni.
E:t
i1ipΓ;x17→Tp1  xni7→TpniEi:T ΓM:T
4/56
LnagyTapgaegdeesPuirtoergmaamtino2L(2P)
Typage du match
Exemple : fact II
# let rec fact n = match n with | 0 -> 1 | n -> n* (fact (n-1)) ; ; val fact : int -> int = <fun>
5
/
56
ngagLarogredePnoitammayT)2PL(2itsugepaedagypeToitpsnnsioceExexesptce566/
E:tE1:tE2(nb) :tE3:tE4:t T:t
(une expression)
tryEwith |ListeVideE1 |Alarme(n,b)E2(nb) |Not_foundE3 |Division_by_zeroE4 E,E1,E2(nb),E3,E4,  doivent avoir lemêmetype, qui est le type de l’expression entièreT.
T
=
LangBialgaendeProgrmaamitno2L(2P)
Rappel des règles de typage
Γ0:int
Γ;x7→tx:t Γx:tx6=y Γ;y7→ux:t ΓB:boolΓE1:tΓE2:t Γ(ifBthenE1elseE2) :t ΓA:tΓB:u Γ(AB) :t×u ΓE1:T1  ΓEn:Tn Γ⊢ {c1=E1;  cn=En}:r
Pour touti1in,
ΓE:r ΓEci:Ti
8/56
LnagBialgaendeProgrmaamtino2L(2P)
Rappel des règles de typage
E:t
ΓA:tuΓB:t ΓA B:u
Γx7→tE:u ΓfunxE:tu
ΓA:tΓx7→tB:u Γletx=AinB:u
Γx7→tA:tΓx7→tB:u Γlet recx=AinB:u
i1ipΓ;x17→Tp1  xni7→Tpni ΓM:T=match
Ei:T
9/65
LangBialgaendeProgrmaamitno2(L2P)
En somme, qu’est-ce qu’un type ?
Moyens de construction élémentaires : (principesd’introduction)
Indiquent les valeurs du type (infos non réductibles) produits (ex. record Pascal, struct C, {} Ocaml, * ML) sommes (sommes ML, articles avec variantes Pascal) exponentielles (fonctions, tableaux)
Procédés d’utilisation élémentaires : (principesd’élimination)
produits (projections, champs) sommes (filtrage) exponentielles (application)
Symétrie introduction / élimination
10 / 56
(fnusuop,pessuopq)seu(|Oq)p,tnE(t,p)qOnu(finpe,nieq)|Ou(p,q)Open,(finei)q
Chercher l’erreur... et la corriger ...par typage pousse ( Neg(Neg(Neg(Et(Vrai,Var("x"))))) ) ; ;
Exercice : repousser les négations vers les extrémités* typeboolexpr= |Vrai|Faux|Varofstring|Negofboolexpr |Etofboolexpr*boolexpr|Ouofboolexpr*boolexpr
2/1
typeboolexprnf= |Vrainf|Fauxnf|Varnfofstring|Negnfofboolexprnf |Etnfofboolexprnf*boolexprnf|Ounfofboolexprnf*boolexprnf
56lan2(LP2)BinoitammargorPedeagngLaE|(t,p)qEnt(fopussep,pousseq)|EaV(f(fnr|))v(geNnp)p|ieg(Nepp)V|raiafnaVnrv()|Varf(v)Negn(v)aFiarV|uaF|fnxunfuxFaxVrxau|Fnie=funconletrecirViafnitnoV|aretluf=eitcnpcerssuo
Lnaageg
Bilan
derPgorammation
Solution*
2(LP2)
(Analyse
par
typage)
14
/
56
Thearityof a symbolf∈ FisArity(f) The set of symbols of aritypis denoted byFp. Elements of arity0,1 . ., .pare respectively called constants, unary, . . .p-ary symbols.
Fis a finite set Arityis a mapping fromFintoN (FArity)is aranked alphabetorsignaturedenotedΣ
Definition
eMssasdneTmritnoica2)Un2(LPtionammargorPedegagnLarAtigasey
16 / 56
  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • Podcasts Podcasts
  • BD BD
  • Documents Documents