Il sistema dei tipi in ML. cenni

Documenti analoghi
Programmazione Funzionale

In questo esempio, il tipo a -> a indica che la funzione fn x => x è polimorfa, ed è dunque corretto applicarla ad argomenti di tipo diverso:

Silvia Crafa

College Algebra. Logarithms: Denitions and Domains. Dr. Nguyen November 9, Department of Mathematics UK

Constant Propagation. A More Complex Semilattice A Nondistributive Framework

Programmazione Definizione di nuovi tipi

ML è un linguaggio interattivo La modalità interattiva di OCaml Ciclo: LETTURA, VALUTAZIONE, STAMPA. Objective Caml version 3.06

Relative error analysis of matrix exponential approximations for numerical integration

Type Assignment System

Analisi semantica. Type Assignment System

Valutazione Lazy. Prefazione alla lezione

Sistemi di tipo e analisi statica

Nonlinear Control Lecture # 12 Passivity. Nonlinear Control

ECOLE POLYTECHNIQlE FEDERALE DE LAUSANNE

Question 1: introduction to computer programming

1 I Tipi nei Linguaggi Funzionali

A.A. 2006/2007 Laurea di Ingegneria Informatica. Fondamenti di C++ Horstmann Capitolo 3: Oggetti Revisione Prof. M. Angelaccio

Funzioni e Spezie. Luca Abeni. March 14, 2016

Linguaggi con Tipi di Ordine Superiori

Fuori programma Kotlin e Android

Programmazione Funzionale

Introduzione alla Teoria dei Giochi

Ottimizzazione Combinatoria J and 6.855J and ESD.78J

Fondamenti di Teoria delle Basi di Dati

COIN TOSSINGS. Contents. 1 Sistemi dinamici a tempo discreto 2. 2 Bernoulli shifts 4. 3 Equivalenza tra sistemi deterministici e stocastici 8

Resources and Tools for Bibliographic Research. Search & Find Using Library Catalogues

Silvia Crafa Primo Semestre AA

Modelli Clamfim info sul corso Differenziabilità, Massimi e minimi liberi 20 settembre 2016

Probability Distributions T O P I C # 1

Clamfim Lesson 6 Giovedì 15 Novembre 2012 Separable equations

Modelli Clamfim Massimi e minimi 30 settembre 2013

Finite Model Theory / Descriptive Complexity: bin

Istruzioni selettive: IF THEN

Clamfim Lesson 15 Lunedì 3 Dicembre 2012 Change of variables. Eulerian integrals

LA SACRA BIBBIA: OSSIA L'ANTICO E IL NUOVO TESTAMENTO VERSIONE RIVEDUTA BY GIOVANNI LUZZI

GARA SECONDARIA SECONDO GRADO - INDIVIDUALI. ESERCIZIO 1 Si faccia riferimento alla GUIDA - OPS 2018, problema ricorrente REGOLE E DEDUZIONI.

Quadrature. Emma Perracchione. Corso di Calcolo Numerico per Ingegneria Meccanica - Matr. PARI (Univ. PD)

ESISTENZA DI INFINITI NUMERI PRIMI REGOLARI. Francesco Di Noto, Michele Nardelli. In this paper we describe about the regular prime

Polimorfismo parametrico

Fisica Computazionale

COMPITO DI FONDAMENTI DI INFORMATICA Allievi Ingegneri Meccanici. Appello dell 11 Febbraio 2008 ( )

Optmization Methods for Machine Learning. Gradient method for multilayer perceptron

Fixpoint ed Altre Amenità

Laboratorio 3 (SmallC: Alberi Astratti con Tipi Algebrici in OCaml)

Limiti di un Elaboratore

MAGNETISM IN STAINLESS STEELS MAGNETISMO NEGLI ACCIAI INOSSIDABILI

Type Assignment System

LIQUID FUEL CHARACTERISTICS

Discrete Parabolic Anderson Model with Heavy Tailed Potential

Puntatori, array, incrementi Array come parametri Array di puntatori. Programmazione 1. Lezione 12. Vincenzo Marra.

Le cellule staminali dell embrione: cosa possono fare Embryonic stem cells are exciting because they can make all the different types of cell in the

Classi di memorizzazione

Inferenza di tipi (polimorfi): in linguaggi funzionali à la ML

New perspectives in the reconstruction of convex polyominoes from orthogonal projections

Linguaggi di Programmazione avanzati Linguaggi funzionali

Le coniche furono studiate già 2000 anni fa dagli antichi Greci in particolare da Apollonio (III secolo a.c) che ne scoprì numerose proprietà.

NATIONAL SPORT SCHOOL

Italian 102 Daily Syllabus

Quasi-uniform Grids and. Ad Hoc Finite Dierence Schemes for BVPs on Innite Intervals. Alessandra Jannelli and Riccardo Fazio

13. Calcolo dei sequenti per logica classica predicativa

LEGEND LEGEND. Vi diamo ARIA da 30 anni! Supplying you AIR for over 30 years! VIA G.PASCOLI, ABBIATEGRASSO (MI) ITALY

let quorem pair = ((fst pair)/(snd pair), (fst pair) mod (snd pair))

Conoscere l uso delle collezioni in Java. Conoscere il concetto di Generics (programmazione

ESERCIZIO 1 Si faccia riferimento all Allegato A - OPS 2016, problema ricorrente REGOLE E DEDUZIONI, pagina 2.

FONDAMENTI DI PROGRAMMAZIONE (A,B,C,D) Soluzione verifica scritta del 21/12/2001

Fourier transform of images

ANELLI INTERNI INNER RINGS

LUBRICATION / LUBRIFICAZIONE

14. Come interpretare unicità? con l uguaglianza

Qui u ck c k PE P R E L

Definizione di nuovi tipi

Algoritmi Priority-Driven RT. Corso di Sistemi RT Prof. Davide Brugali Università degli Studi di Bergamo

Problema: stampa degli interi compresi tra n e m

UNIVERSITÀ DEGLI STUDI DI TORINO

Clamfim Lesson 12 Martedì 27 Novembre 2012 Passage to the limit

100 consigli per vivere bene (Italian Edition)

LA SACRA BIBBIA: OSSIA L'ANTICO E IL NUOVO TESTAMENTO VERSIONE RIVEDUTA BY GIOVANNI LUZZI

Nonlinear systems. Phase plane analysis. G. Ferrari Trecate

COMPITO DI FONDAMENTI DI INFORMATICA Allievi Ingegneri Meccanici. Lunedì 20 Febbraio 2006 ( )

The normal gravity formula and the polar flattening according to geodetic reference system 1967

~` Read Aumentare La Massa Muscolare: Come Far Crescere I Tuoi Muscoli E Allenare La Tua Massa Muscolare - Aumenta La... books download free audio

AIM OF THE LESSON: for the students to familiarise themselves with the language of cooking

WEB OF SCIENCE. COVERAGE: multidisciplinary TIME RANGE: DOCUMENT TYPES: articles, proceedings papers, books

Statistica Di Base Con Aggiornamento Online

Lecture 7: Quadratic optimization

Mini linguaggio funzionale. FuncConal programming in Java8. Linguaggi funzionali. Teoria dei Linguaggi di Programmazione

ESERCIZIO 1 Si faccia riferimento alla GUIDA - OPS 2017, problema ricorrente REGOLE E DEDUZIONI.

Le piccole cose che fanno dimagrire: Tutte le mosse vincenti per perdere peso senza dieta (Italian Edition)

I Sistemi Lineari 10 Zanichelli Online Per La Scuola

PDE lineari primo ordine

Semantica statica e dinamica

Downloading and Installing Software Socio TIS

Classi di memorizzazione

REGISTRATION GUIDE TO RESHELL SOFTWARE

Gocce d'anima (Italian Edition)

Fiori di campo. Conoscere, riconoscere e osservare tutte le specie di fiori selvatici più note

PRIMA PROVA SCRITTA: ELENCO DOMANDE

PROGRAMMAZIONE Realizzare un interprete in OCaML

Transcript:

Il sistema dei tipi in ML cenni

Inferenza tipi ML - val f = fn x => x+1; val f = fn : int -> int - f 2; val it = 3 : int - - fun f(x) = x+1; val f = fn : int -> int - f 2; val it = 3 : int -

- val g = fn (x,y) => x+y; val g = fn : int * int -> int - fn (x,y) => x+y; val it = fn : int * int -> int - fn (x,y) => x+y+3.5; val it = fn : real * real -> real meccanismo per dare un nome a termini fun f x 1 x 2... x n = M; val g = M; val f = fn x=> x+1; fun f(x)= x+1; val f = fn x 1 => (fn x 2 => (... =>(fn x n => M)...))

i termini di un mini ML sono parametro corpo della funzione funzione argomento formale fn x M x M(N) +,-,..., 0,1,... termini buit-in variabile

I tipi: t::= int t1 t2 indichiamo con M:t il fatto che M ha tipo t : int (int int), 0:int, 1:int... assumendo che x:u abbiamo che x:u se M: t u e N:t allora M(N):u se M:u nellʼassunzione che x:t allora (cancellando lʼassunzione x:t) fn x M: t u

Tipi/Logica/Deduzione naturale x:u _ : int (int int) 0:int 1:int [x:t] M: t u N:t. M(N):u M:u. fn x M: t u

Γ,x:u x:u Γ : int (int int) Γ 0:int Γ 1:int Γ è un insieme x 1 :t 1,..,x n :t n Assunzioni/Contesto/Ambiente... Γ n:int... Γ M: t u Γ N:t. Γ M(N):u Γ Γ,x:t M:u. fn x M: t u

val f = fn x=> ( x) 1; val f = fn : int -> int x:int : int (int int) x:int x: int int x:int x: int x:int 1: int x:int ( x)1: int fn x=> ( x) 1: int -> int

val id = fn x=> x; val id = fn :??? quale è il tipo di id? per ogni tipo t abbiamo la seguente derivazione corretta di tipo x:t x:t fn x =>x : t t l'idea è che id abbia tipo α. α α ('a->'a nella sintassi ML) dove α è una variabile di tipo e è un quantificatore del secondo ordine (quantifica rispetto alla classe dei tipi)

occorre quindi arricchire i tipi con: 1.variabili di tipo (α,β,...) 2.quantificazioni di tipo la trattazione tecnica rigorosa esula dagli scopi di questo corso :-( diamo un cenno al sistema di tipi

I tipi t::= int α t 1 t 2 Schemi di tipo σ::= t α. σ α è una variabile di tipo sostituzione σ'=σ[t/α] Un termine chiuso M è tipabile se è possibile derivare per M uno schema di tipo chiuso (senza variabili di tipo libere) ovvero o un tipo t senza variabili di tipo oppure uno schema α 1...α n.t dove α 1...α n sono tutte e sole le variabili di tipo in t)

Γ,x:u x:u Γ : int (int int) Γ è un insieme x 1 :t 1,..,x n :t n Assunzioni/Contesto/Ambiente Γ 0:int Γ 1:int Γ n:int...... Γ M: t u Γ N:t. Γ M(N):u Γ M: σ. Γ M: α. σ α non deve occorrere in Γ Γ Γ,x:t M:u. fn x M: t u Γ M: α. σ. Γ M: σ[t/α]

Il caso delle dichiarazioni locali Γ è un insieme x 1 :σ 1,..,x n :σ n (t,u tipi, σ schema di tipo) Γ,x:σ x:σ Γ 0:int Γ 1:int Γ n:int Γ Γ,x:t M:u. fn x M: t u Γ : int (int int) Γ M: t u Γ N:t. Γ M(N):u Γ M: σ. Γ M: α. σ α non deve occorrere libera in Γ Γ Γ M: σ Γ,z:σ N:t. let val z=m in N end:t Γ M: α. σ. Γ M: σ[t/α]

x:α x:α fn x =>x : α α fn x =>x : α. α α val id = fn x=> x; val id = fn : α. α α val f = fn x=> ( x) 1; val f = fn : int -> int id : α. α α id : α. α α id : (int int) (int int) f: int int id : int int 2 : int id f : int int id 2 : int (id f)(id 2) : int id è una funzione polimorfa

The generalises relation We say a type scheme generalises a type, and write if can be obtained from the type by simultaneously substituting some types for the type variables ( ): Typeable closed expressions We write to indicate that is closed expression (i.e. has no free variables) is a closed type scheme (i.e. is of the form with all the type variables occurring in the type contained in the set ) (N.B. The relation is unaffected by the particular choice of names of bound type variables in.) The converse relation is called specialisation: a type specialisation of a type scheme if. is a Principal type schemes A closed type scheme ML expression if is the principal type scheme of a closed (a) (b) for all closed, if then where by definition holds if generalises in the sense of Slide 16. (We are assuming the type schemes are closed, so in particular all the type variables of are in.)

esercizi fn x =>x : α. α α (fn x =>x)(fn x =>x) : α. α α fn x =>x(x): NON è TIPABILE let val f = fn x => x in f(f) end: α. α α