• Keine Ergebnisse gefunden

Existen(al  Types

N/A
N/A
Protected

Academic year: 2022

Aktie "Existen(al  Types"

Copied!
13
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Existen(al  Types  

Klaus  Ostermann   University  of  Tübingen  

(2)

Existen(al  Types  

•  Are  „dual  to  universal  types  

•  Founda(on  for  data  abstrac(on  and  informa(on   hiding  

•  Two  ways  to  look  at  an  existen(al  type   {X,T}  

–  Logical  intui(on:  a  value  of  type  T[X:=S]  for  some  type  S   –  Opera(onal  intui(on:  a  pair  {*S,t}  of  a  type  S  and  term  t  of  

type  T[X:=S]  

•  Other  books  use  the  (more  standard)  nota(on  X.T.  

We  s(ck  to  Pierces  nota(on   {X,T}  

(3)

Building  and  using  terms  with   existen(al  types  

•  Or,  in  the  terminology  of  natural  deduc(on,   introduc)on  and  elimina)on  rules  

•  Idea:  A  term  can  be  packed  to  hide  a  type   component,  and  unpacked  (or:  openend)  to   use  it  

(4)

Example  

(5)

Example  

(6)

Existen(al  Types  

(7)

Encoding  existen(al  types  by   universal  types  

•  In  logic  we  have  

•  We  can  simulate  an  existen(al  type  by  a   universal  type  and  a  “con(nua(on”  

•  Recall  that,  via  Curry-­‐Howard,  CPS  

transforma(on  corresponds  to  double   nega(on!  

(8)

Encoding  existen(al  types  by   universal  types  

•  Packing  

•  Unpacking  

(9)

Forms  of  existen(al  types:  SML  

signature INT_QUEUE = sig type t

val empty : t

val insert : int * t -> t val remove : t -> int * t end

(10)

Forms  of  existen(al  types:  SML  

structure IQ :> INT_QUEUE = struct type t = int list

val empty = nil

val insert = op ::

fun remove q =

let val x::qr = rev q in (x, rev qr) end

end

structure Client = struct

… IQ.insert … IQ.remove … end

(11)

Open  vs  closed  Scope  

•  Existen(als  via  pack/unpack  provide  no  direct   access  to  hidden  type  (closed  scope)  

– If  we  open  an  existen(al  package  twice,  we  get   two  different  abstract  types!  

•  If  S  is  an  SML  module  with  hidden  type  t,  then   each  occurrence  of  S.t  refers  to  the  same  

unknown  type  

– SML  modules  are  not  first-­‐class  whereas  pack/

unpack  terms  are  

(12)

Forms  of  existen(al  types:  Java  Wildcards  

From: “Towards an Existential Types Model for Java Wildcards”, FTFJP 2007

(13)

Forms  of  existen(al  types:  

Existen(ally  quan(fied  data  constructors  in  Haskell

 

data Obj = forall a. (Show a) => Obj a

xs :: [Obj]

xs = [Obj 1, Obj "foo", Obj 'c']

doShow :: [Obj] -> String doShow [] = ""

doShow ((Obj x):xs) = show x ++ doShow xs

Referenzen

ÄHNLICHE DOKUMENTE

This is basically a copy of the STLC “one

• In our case: Use directed variant of type equivalence relation, reduce until normal form reached. • In practical languages, a slightly weaker

• Existentials via pack/unpack provide no direct access to hidden type (closed scope). – If we open an existential package twice, we get two different

In the summer of 1963 we had conversations in which he explained to me that he had developed a theory of infinite terms in analogy to Schtte’s theory of infinite proofs,

1 Index Tuning Query Types Index Types Data Structures Composite Indexes Indexes and Joins Index Tuning Examples.. Augsten (Univ. Salzburg) DBT – Index Tuning Sommersemester 2019 2

Haga clic en este botón si desea recuperar todos los ajustes de marca de fondo que figuraban en el cuadro de diálogo Previsualización Impresión EPSON la primera vez que lo

Seleccione Alimentador de hojas como Fuente papel (Windows)/Origen de papel (Macintosh) y el Tamaño papel que va a utilizar en el menú Papel (Windows) o el cuadro de diálogo

El tractor pull es el más adecuado para impedir que se atasque el papel, y le permite cargar papel continuo en la ranura frontal, la posterior o la inferior de la impresora..