SlideShare a Scribd company logo
1 of 12
Download to read offline
Dependent pair type (Σ-type)
Dmytro Mitin
https://stepik.org/course/Introduction-to-programming-
with-dependent-types-in-Scala-2294/
March 2017
Dmytro Mitin Dependent pair type (Σ-type)
Sets
Union of set family
α∈A
Bα = b ∃α ∈ A b ∈ Bα
Disjoint union of set family
α∈A
Bα = (α, b) α ∈ A , b ∈ Bα
Dmytro Mitin Dependent pair type (Σ-type)
Dependent pair type (Σ-type)
1 Type Formation
Γ A : ∗ Γ, x : A B : ∗
Γ
x:A
B : ∗
2 Constructor
Γ a : A Γ, x : A B : ∗ Γ b : B[x ← a]
Γ (a, b) :
x:A
B
3 Eliminators
Γ p :
x:A
B
Γ fst p : A
Γ p :
x:A
B
Γ snd p : B[x ← fst p]
Dmytro Mitin Dependent pair type (Σ-type)
Dependent pair type (Σ-type)
4 Computation rules (”β-reduction“)
Γ a : A Γ, x : A B : ∗ Γ b : B[x ← a]
Γ fst(a, b) ≡ a : A
Γ a : A Γ, x : A B : ∗ Γ b : B[x ← a]
Γ snd(a, b) ≡ b : B
5 Uniqueness principle (”η-conversion“)
Γ p :
x:A
B
Γ (fst p, snd p) ≡ p :
x:A
B
Dmytro Mitin Dependent pair type (Σ-type)
Partial case
Partial case of
x:A
B
is sum type (coproduct)
B1 + B2
Dmytro Mitin Dependent pair type (Σ-type)
Idris
data DepPair : (a : Type) -> (P : a -> Type) -> Type where
MakeDepPair : {P : a -> Type} -> (x : a) -> P x -> DepPair a P
depType : Int -> Type
depType 0 = Int
depType 1 = String
depType = Bool
x : DepPair Int (n => depType n)
x = MakeDepPair 1 "a"
x1 : DepPair Int (n => depType n)
x1 = MakeDepPair 0 10
x2 : DepPair Int (n => depType n)
x2 = MakeDepPair 2 True
Dmytro Mitin Dependent pair type (Σ-type)
Idris
x3 : DepPair Int (n => depType n)
x3 = MakeDepPair 0 "a"
Dmytro Mitin Dependent pair type (Σ-type)
Scala
sealed trait Nat {
type This >: this.type <: Nat
type ++ = Succ[This]
}
final object Zero extends Nat {
type This = Zero
}
type Zero = Zero.type
final class Succ[N <: Nat] extends Nat {
type This = Succ[N]
}
Dmytro Mitin Dependent pair type (Σ-type)
Scala
type 0 = Zero
type 1 = 0 # ++
type 2 = 1 # ++
type 3 = 2 # ++
val 0: 0 = Zero
val 1: 1 = new Succ[ 0]
val 2: 2 = new Succ[ 1]
val 3: 3 = new Succ[ 2]
Dmytro Mitin Dependent pair type (Σ-type)
Scala
sealed trait DepType[N <: Nat] { type T }
implicit object depType0 extends DepType[ 0] { type T = Int }
implicit object depType1 extends DepType[ 1] { type T = String }
implicit def depType[N <: Nat] = new DepType[Succ[Succ[N]]] {
type T = Boolean }
case class DepPair[N <: Nat, V](x: N, value: V)(implicit
depType: DepType[N] { type T = V })
DepPair( 0, 10)
DepPair( 1, "aaa")
DepPair( 2, true)
DepPair( 2, "bbb") // error
DepPair( 3, false)
Dmytro Mitin Dependent pair type (Σ-type)
ProvingGround. Built-in type
git clone https://github.com/siddhartha-gadgil/ProvingGround.git
cd ProvingGround
sbt mantle/test:console
val A = "A" :: Type
val B = "B( : A)" :: A ->: Type
val a = "a" :: A
val b = "b" :: B(a)
val pair = mkPair(a, b) !: Sgma(a !: A, B(a))
val recSABA = Sgma(a !: A, B(a)).rec(A)
val first = recSABA(a :∼> (b :-> a))
first(pair) == a
val recSABSAB = Sgma(a !: A, B(a)).rec(Sgma(a !: A, B(a)))
val id = recSABSAB(a :∼> (b :->
mkPair(a, b).asInstanceOf[DepPair[Term, Term]]))
id(pair) == pair
Dmytro Mitin Dependent pair type (Σ-type)
ProvingGround. Custom type
import TLImplicits.
import shapeless.
val A = "A" :: Type
val B = "B( : A)" :: A ->: Type
val a = "a" :: A
val b = "b" :: B(a)
val SigmaAB = "Sigma(a : A, B(a))" :: Type
val SigmaInd = ("mkPair" ::: a ∼>>: (B(a) ->>: SigmaAB))
=: SigmaAB
val makePair :: HNil = SigmaInd.intros
val pair = makePair(a)(b) !: SigmaAB
val recSABA = SigmaInd.rec(A)
val first = recSABA(a :∼> (b :-> a))
first(pair) == a
val recSABSAB = SigmaInd.rec(SigmaAB)
val id = recSABSAB(a :∼> (b :-> makePair(a)(b)))
id(pair) == pair
Dmytro Mitin Dependent pair type (Σ-type)

More Related Content

What's hot

Rails Text Mate Cheats
Rails Text Mate CheatsRails Text Mate Cheats
Rails Text Mate Cheatsdezarrolla
 
บทที่ 3 พื้นฐานภาษา Java
บทที่ 3 พื้นฐานภาษา Javaบทที่ 3 พื้นฐานภาษา Java
บทที่ 3 พื้นฐานภาษา JavaItslvle Parin
 
Peyton jones-2009-fun with-type_functions-slide
Peyton jones-2009-fun with-type_functions-slidePeyton jones-2009-fun with-type_functions-slide
Peyton jones-2009-fun with-type_functions-slideTakayuki Muranushi
 
「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)Hiroki Mizuno
 
09 - Scala. Product type
09 - Scala. Product type09 - Scala. Product type
09 - Scala. Product typeRoman Brovko
 
Constructor in c++
Constructor in c++Constructor in c++
Constructor in c++Jay Patel
 
Number System in Haskell
Number System in Haskell Number System in Haskell
Number System in Haskell Yun-Yan Chi
 
Peyton jones-2011-type classes
Peyton jones-2011-type classesPeyton jones-2011-type classes
Peyton jones-2011-type classesTakayuki Muranushi
 
vbscript-reference book
vbscript-reference bookvbscript-reference book
vbscript-reference bookAnand Dhana
 
WAP to initialize different objects with different values in java
WAP to initialize different objects with different values in javaWAP to initialize different objects with different values in java
WAP to initialize different objects with different values in javaOne97 Communications Limited
 
05 - Scala. List type
05 - Scala. List type05 - Scala. List type
05 - Scala. List typeRoman Brovko
 

What's hot (18)

Rails Text Mate Cheats
Rails Text Mate CheatsRails Text Mate Cheats
Rails Text Mate Cheats
 
บทที่ 3 พื้นฐานภาษา Java
บทที่ 3 พื้นฐานภาษา Javaบทที่ 3 พื้นฐานภาษา Java
บทที่ 3 พื้นฐานภาษา Java
 
ATS Programming
ATS ProgrammingATS Programming
ATS Programming
 
Peyton jones-2009-fun with-type_functions-slide
Peyton jones-2009-fun with-type_functions-slidePeyton jones-2009-fun with-type_functions-slide
Peyton jones-2009-fun with-type_functions-slide
 
「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)
 
09 - Scala. Product type
09 - Scala. Product type09 - Scala. Product type
09 - Scala. Product type
 
Constructor in c++
Constructor in c++Constructor in c++
Constructor in c++
 
Number System in Haskell
Number System in Haskell Number System in Haskell
Number System in Haskell
 
Peyton jones-2011-type classes
Peyton jones-2011-type classesPeyton jones-2011-type classes
Peyton jones-2011-type classes
 
Data Applied:Outliers
Data Applied:OutliersData Applied:Outliers
Data Applied:Outliers
 
vbscript-reference book
vbscript-reference bookvbscript-reference book
vbscript-reference book
 
WAP to initialize different objects with different values in java
WAP to initialize different objects with different values in javaWAP to initialize different objects with different values in java
WAP to initialize different objects with different values in java
 
Oop concepts
Oop conceptsOop concepts
Oop concepts
 
Clojure Linters
Clojure LintersClojure Linters
Clojure Linters
 
Dynamic grammars
Dynamic grammarsDynamic grammars
Dynamic grammars
 
05 - Scala. List type
05 - Scala. List type05 - Scala. List type
05 - Scala. List type
 
Learn Java Part 11
Learn Java Part 11Learn Java Part 11
Learn Java Part 11
 
Boolean type
Boolean typeBoolean type
Boolean type
 

Similar to 13 - Scala. Dependent pair type (Σ-type)

15 - Scala. Dependent function type (Π-type)
15 - Scala. Dependent function type (Π-type)15 - Scala. Dependent function type (Π-type)
15 - Scala. Dependent function type (Π-type)Roman Brovko
 
10 - Scala. Co-product type (sum type)
10 - Scala. Co-product type (sum type)10 - Scala. Co-product type (sum type)
10 - Scala. Co-product type (sum type)Roman Brovko
 
16 - Scala. Type of length-indexed vectors
16 - Scala. Type of length-indexed vectors16 - Scala. Type of length-indexed vectors
16 - Scala. Type of length-indexed vectorsRoman Brovko
 
04 - Scala. Type of natural numbers
04 - Scala. Type of natural numbers04 - Scala. Type of natural numbers
04 - Scala. Type of natural numbersRoman Brovko
 
Type-level programming
Type-level programmingType-level programming
Type-level programmingDmytro Mitin
 
22 - Scala. Type-level programming. Shapeless
22 - Scala. Type-level programming. Shapeless22 - Scala. Type-level programming. Shapeless
22 - Scala. Type-level programming. ShapelessRoman Brovko
 
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)François Sarradin
 
08 - Scala. Type classes. Simulacrum
08 - Scala. Type classes. Simulacrum08 - Scala. Type classes. Simulacrum
08 - Scala. Type classes. SimulacrumRoman Brovko
 
19 - Scala. Eliminators into dependent types (induction)
19 - Scala. Eliminators into dependent types (induction)19 - Scala. Eliminators into dependent types (induction)
19 - Scala. Eliminators into dependent types (induction)Roman Brovko
 
Eliminators into dependent types
Eliminators into dependent typesEliminators into dependent types
Eliminators into dependent typesDmytro Mitin
 
11 - Scala. Function type
11 - Scala. Function type11 - Scala. Function type
11 - Scala. Function typeRoman Brovko
 
12 - Scala. Empty and unit types
12 - Scala. Empty and unit types12 - Scala. Empty and unit types
12 - Scala. Empty and unit typesRoman Brovko
 
User Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryUser Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryDatabricks
 
User Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryUser Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryDatabricks
 
Plot3D Package and Example in R.-Data visualizat,on
Plot3D Package and Example in R.-Data visualizat,onPlot3D Package and Example in R.-Data visualizat,on
Plot3D Package and Example in R.-Data visualizat,onDr. Volkan OBAN
 
Plot3D package in R-package-for-3d-and-4d-graph-Data visualization.
Plot3D package in R-package-for-3d-and-4d-graph-Data visualization.Plot3D package in R-package-for-3d-and-4d-graph-Data visualization.
Plot3D package in R-package-for-3d-and-4d-graph-Data visualization.Dr. Volkan OBAN
 
Type Classes in Scala and Haskell
Type Classes in Scala and HaskellType Classes in Scala and Haskell
Type Classes in Scala and HaskellHermann Hueck
 
Document Classification In PHP - Slight Return
Document Classification In PHP - Slight ReturnDocument Classification In PHP - Slight Return
Document Classification In PHP - Slight ReturnIan Barber
 

Similar to 13 - Scala. Dependent pair type (Σ-type) (20)

15 - Scala. Dependent function type (Π-type)
15 - Scala. Dependent function type (Π-type)15 - Scala. Dependent function type (Π-type)
15 - Scala. Dependent function type (Π-type)
 
10 - Scala. Co-product type (sum type)
10 - Scala. Co-product type (sum type)10 - Scala. Co-product type (sum type)
10 - Scala. Co-product type (sum type)
 
16 - Scala. Type of length-indexed vectors
16 - Scala. Type of length-indexed vectors16 - Scala. Type of length-indexed vectors
16 - Scala. Type of length-indexed vectors
 
04 - Scala. Type of natural numbers
04 - Scala. Type of natural numbers04 - Scala. Type of natural numbers
04 - Scala. Type of natural numbers
 
Type-level programming
Type-level programmingType-level programming
Type-level programming
 
22 - Scala. Type-level programming. Shapeless
22 - Scala. Type-level programming. Shapeless22 - Scala. Type-level programming. Shapeless
22 - Scala. Type-level programming. Shapeless
 
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)
 
08 - Scala. Type classes. Simulacrum
08 - Scala. Type classes. Simulacrum08 - Scala. Type classes. Simulacrum
08 - Scala. Type classes. Simulacrum
 
19 - Scala. Eliminators into dependent types (induction)
19 - Scala. Eliminators into dependent types (induction)19 - Scala. Eliminators into dependent types (induction)
19 - Scala. Eliminators into dependent types (induction)
 
Eliminators into dependent types
Eliminators into dependent typesEliminators into dependent types
Eliminators into dependent types
 
11 - Scala. Function type
11 - Scala. Function type11 - Scala. Function type
11 - Scala. Function type
 
12 - Scala. Empty and unit types
12 - Scala. Empty and unit types12 - Scala. Empty and unit types
12 - Scala. Empty and unit types
 
User Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryUser Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love Story
 
User Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryUser Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love Story
 
Plot3D Package and Example in R.-Data visualizat,on
Plot3D Package and Example in R.-Data visualizat,onPlot3D Package and Example in R.-Data visualizat,on
Plot3D Package and Example in R.-Data visualizat,on
 
Plot3D package in R-package-for-3d-and-4d-graph-Data visualization.
Plot3D package in R-package-for-3d-and-4d-graph-Data visualization.Plot3D package in R-package-for-3d-and-4d-graph-Data visualization.
Plot3D package in R-package-for-3d-and-4d-graph-Data visualization.
 
Scala jargon cheatsheet
Scala jargon cheatsheetScala jargon cheatsheet
Scala jargon cheatsheet
 
Type Classes in Scala and Haskell
Type Classes in Scala and HaskellType Classes in Scala and Haskell
Type Classes in Scala and Haskell
 
Document Classification In PHP - Slight Return
Document Classification In PHP - Slight ReturnDocument Classification In PHP - Slight Return
Document Classification In PHP - Slight Return
 
SacalaZa #1
SacalaZa #1SacalaZa #1
SacalaZa #1
 

More from Roman Brovko

Individual task Networking
Individual task NetworkingIndividual task Networking
Individual task NetworkingRoman Brovko
 
Networking essentials lect3
Networking essentials lect3Networking essentials lect3
Networking essentials lect3Roman Brovko
 
Gl embedded starterkit_ethernet
Gl embedded starterkit_ethernetGl embedded starterkit_ethernet
Gl embedded starterkit_ethernetRoman Brovko
 
Networking essentials lect2
Networking essentials lect2Networking essentials lect2
Networking essentials lect2Roman Brovko
 
Networking essentials lect1
Networking essentials lect1Networking essentials lect1
Networking essentials lect1Roman Brovko
 
Bare metal training_07_spi_flash
Bare metal training_07_spi_flashBare metal training_07_spi_flash
Bare metal training_07_spi_flashRoman Brovko
 
Bare metal training_06_I2C
Bare metal training_06_I2CBare metal training_06_I2C
Bare metal training_06_I2CRoman Brovko
 
Bare metal training_05_uart
Bare metal training_05_uartBare metal training_05_uart
Bare metal training_05_uartRoman Brovko
 
Bare metal training_04_adc_temp_sensor
Bare metal training_04_adc_temp_sensorBare metal training_04_adc_temp_sensor
Bare metal training_04_adc_temp_sensorRoman Brovko
 
Bare metal training_03_timers_pwm
Bare metal training_03_timers_pwmBare metal training_03_timers_pwm
Bare metal training_03_timers_pwmRoman Brovko
 
Bare metal training_02_le_ds_and_buttons
Bare metal training_02_le_ds_and_buttonsBare metal training_02_le_ds_and_buttons
Bare metal training_02_le_ds_and_buttonsRoman Brovko
 
Bare metal training_01_hello_world
Bare metal training_01_hello_worldBare metal training_01_hello_world
Bare metal training_01_hello_worldRoman Brovko
 
Bare metal training_00_prerequisites
Bare metal training_00_prerequisitesBare metal training_00_prerequisites
Bare metal training_00_prerequisitesRoman Brovko
 
C language lect_23_advanced
C language lect_23_advancedC language lect_23_advanced
C language lect_23_advancedRoman Brovko
 
C language lect_22_advanced
C language lect_22_advancedC language lect_22_advanced
C language lect_22_advancedRoman Brovko
 
C language lect_21_advanced
C language lect_21_advancedC language lect_21_advanced
C language lect_21_advancedRoman Brovko
 
подготовка рабочего окружения
подготовка рабочего окруженияподготовка рабочего окружения
подготовка рабочего окруженияRoman Brovko
 
C language lect_20_advanced
C language lect_20_advancedC language lect_20_advanced
C language lect_20_advancedRoman Brovko
 
C language lect_19_basics
C language lect_19_basicsC language lect_19_basics
C language lect_19_basicsRoman Brovko
 

More from Roman Brovko (20)

Individual task Networking
Individual task NetworkingIndividual task Networking
Individual task Networking
 
Networking essentials lect3
Networking essentials lect3Networking essentials lect3
Networking essentials lect3
 
Gl embedded starterkit_ethernet
Gl embedded starterkit_ethernetGl embedded starterkit_ethernet
Gl embedded starterkit_ethernet
 
Networking essentials lect2
Networking essentials lect2Networking essentials lect2
Networking essentials lect2
 
Networking essentials lect1
Networking essentials lect1Networking essentials lect1
Networking essentials lect1
 
Bare metal training_07_spi_flash
Bare metal training_07_spi_flashBare metal training_07_spi_flash
Bare metal training_07_spi_flash
 
Bare metal training_06_I2C
Bare metal training_06_I2CBare metal training_06_I2C
Bare metal training_06_I2C
 
Glesk worshop
Glesk worshopGlesk worshop
Glesk worshop
 
Bare metal training_05_uart
Bare metal training_05_uartBare metal training_05_uart
Bare metal training_05_uart
 
Bare metal training_04_adc_temp_sensor
Bare metal training_04_adc_temp_sensorBare metal training_04_adc_temp_sensor
Bare metal training_04_adc_temp_sensor
 
Bare metal training_03_timers_pwm
Bare metal training_03_timers_pwmBare metal training_03_timers_pwm
Bare metal training_03_timers_pwm
 
Bare metal training_02_le_ds_and_buttons
Bare metal training_02_le_ds_and_buttonsBare metal training_02_le_ds_and_buttons
Bare metal training_02_le_ds_and_buttons
 
Bare metal training_01_hello_world
Bare metal training_01_hello_worldBare metal training_01_hello_world
Bare metal training_01_hello_world
 
Bare metal training_00_prerequisites
Bare metal training_00_prerequisitesBare metal training_00_prerequisites
Bare metal training_00_prerequisites
 
C language lect_23_advanced
C language lect_23_advancedC language lect_23_advanced
C language lect_23_advanced
 
C language lect_22_advanced
C language lect_22_advancedC language lect_22_advanced
C language lect_22_advanced
 
C language lect_21_advanced
C language lect_21_advancedC language lect_21_advanced
C language lect_21_advanced
 
подготовка рабочего окружения
подготовка рабочего окруженияподготовка рабочего окружения
подготовка рабочего окружения
 
C language lect_20_advanced
C language lect_20_advancedC language lect_20_advanced
C language lect_20_advanced
 
C language lect_19_basics
C language lect_19_basicsC language lect_19_basics
C language lect_19_basics
 

Recently uploaded

Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 

Recently uploaded (20)

Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 

13 - Scala. Dependent pair type (Σ-type)

  • 1. Dependent pair type (Σ-type) Dmytro Mitin https://stepik.org/course/Introduction-to-programming- with-dependent-types-in-Scala-2294/ March 2017 Dmytro Mitin Dependent pair type (Σ-type)
  • 2. Sets Union of set family α∈A Bα = b ∃α ∈ A b ∈ Bα Disjoint union of set family α∈A Bα = (α, b) α ∈ A , b ∈ Bα Dmytro Mitin Dependent pair type (Σ-type)
  • 3. Dependent pair type (Σ-type) 1 Type Formation Γ A : ∗ Γ, x : A B : ∗ Γ x:A B : ∗ 2 Constructor Γ a : A Γ, x : A B : ∗ Γ b : B[x ← a] Γ (a, b) : x:A B 3 Eliminators Γ p : x:A B Γ fst p : A Γ p : x:A B Γ snd p : B[x ← fst p] Dmytro Mitin Dependent pair type (Σ-type)
  • 4. Dependent pair type (Σ-type) 4 Computation rules (”β-reduction“) Γ a : A Γ, x : A B : ∗ Γ b : B[x ← a] Γ fst(a, b) ≡ a : A Γ a : A Γ, x : A B : ∗ Γ b : B[x ← a] Γ snd(a, b) ≡ b : B 5 Uniqueness principle (”η-conversion“) Γ p : x:A B Γ (fst p, snd p) ≡ p : x:A B Dmytro Mitin Dependent pair type (Σ-type)
  • 5. Partial case Partial case of x:A B is sum type (coproduct) B1 + B2 Dmytro Mitin Dependent pair type (Σ-type)
  • 6. Idris data DepPair : (a : Type) -> (P : a -> Type) -> Type where MakeDepPair : {P : a -> Type} -> (x : a) -> P x -> DepPair a P depType : Int -> Type depType 0 = Int depType 1 = String depType = Bool x : DepPair Int (n => depType n) x = MakeDepPair 1 "a" x1 : DepPair Int (n => depType n) x1 = MakeDepPair 0 10 x2 : DepPair Int (n => depType n) x2 = MakeDepPair 2 True Dmytro Mitin Dependent pair type (Σ-type)
  • 7. Idris x3 : DepPair Int (n => depType n) x3 = MakeDepPair 0 "a" Dmytro Mitin Dependent pair type (Σ-type)
  • 8. Scala sealed trait Nat { type This >: this.type <: Nat type ++ = Succ[This] } final object Zero extends Nat { type This = Zero } type Zero = Zero.type final class Succ[N <: Nat] extends Nat { type This = Succ[N] } Dmytro Mitin Dependent pair type (Σ-type)
  • 9. Scala type 0 = Zero type 1 = 0 # ++ type 2 = 1 # ++ type 3 = 2 # ++ val 0: 0 = Zero val 1: 1 = new Succ[ 0] val 2: 2 = new Succ[ 1] val 3: 3 = new Succ[ 2] Dmytro Mitin Dependent pair type (Σ-type)
  • 10. Scala sealed trait DepType[N <: Nat] { type T } implicit object depType0 extends DepType[ 0] { type T = Int } implicit object depType1 extends DepType[ 1] { type T = String } implicit def depType[N <: Nat] = new DepType[Succ[Succ[N]]] { type T = Boolean } case class DepPair[N <: Nat, V](x: N, value: V)(implicit depType: DepType[N] { type T = V }) DepPair( 0, 10) DepPair( 1, "aaa") DepPair( 2, true) DepPair( 2, "bbb") // error DepPair( 3, false) Dmytro Mitin Dependent pair type (Σ-type)
  • 11. ProvingGround. Built-in type git clone https://github.com/siddhartha-gadgil/ProvingGround.git cd ProvingGround sbt mantle/test:console val A = "A" :: Type val B = "B( : A)" :: A ->: Type val a = "a" :: A val b = "b" :: B(a) val pair = mkPair(a, b) !: Sgma(a !: A, B(a)) val recSABA = Sgma(a !: A, B(a)).rec(A) val first = recSABA(a :∼> (b :-> a)) first(pair) == a val recSABSAB = Sgma(a !: A, B(a)).rec(Sgma(a !: A, B(a))) val id = recSABSAB(a :∼> (b :-> mkPair(a, b).asInstanceOf[DepPair[Term, Term]])) id(pair) == pair Dmytro Mitin Dependent pair type (Σ-type)
  • 12. ProvingGround. Custom type import TLImplicits. import shapeless. val A = "A" :: Type val B = "B( : A)" :: A ->: Type val a = "a" :: A val b = "b" :: B(a) val SigmaAB = "Sigma(a : A, B(a))" :: Type val SigmaInd = ("mkPair" ::: a ∼>>: (B(a) ->>: SigmaAB)) =: SigmaAB val makePair :: HNil = SigmaInd.intros val pair = makePair(a)(b) !: SigmaAB val recSABA = SigmaInd.rec(A) val first = recSABA(a :∼> (b :-> a)) first(pair) == a val recSABSAB = SigmaInd.rec(SigmaAB) val id = recSABSAB(a :∼> (b :-> makePair(a)(b))) id(pair) == pair Dmytro Mitin Dependent pair type (Σ-type)