SlideShare a Scribd company logo
Зависимые типы в GHC 8
Максим Талдыкин
max@formalmethods.ru
Что такое?
Just 1 : Maybe Int : * : □
Maybe : * -> * : □
Vec Int Z : * : □
Vec : * -> Nat -> * : □
map : forall a b. (a -> b) -> [a] -> [b]
map f (x:xs) = f x : map f xs
map f [] = []
map :: forall a b. (a -> b) -> [a] -> [b]
map =
 (@a)
(@b)
(f :: a -> b)
(ds :: [a]) ->
case ds of
[] -> GHC.Types.[] @b
: x xs ->
GHC.Types.: @b (f x) (map @a @b f xs)
forall
(a :: *)
(b :: *)
(f :: a -> b)
(xs :: [a])
. [b]
replicate :: pi (n : Nat) -> a -> Vec a n
replicate Z _ = Nil
replicate (S m) x = x :> replicate m a
vis dep rel
forall (a : *). a - + -
a -> a + - +
Monad m => m a - - +
pi (a : Bool). f a - + +
pi (a : Bool) -> f a + + +
* : *
pi
Зачем?
zipWithN, mapT
tail []
strncpy
:: forall (p q :: Nat)
=> (LE n p ~ True, LE n q ~ True)
. pi (n :: Nat)
-> Ptr Char p
-> Ptr Char q
-> IO ()
Π-Ware: Hardware Description
Swierstra et al., 2015
Correct-by-Construction Concurrency
Brady & Hammond, 2009
Security-Typed Programming
Morgenstern & Licata, 2010
Type Families
data Nat = Z | S Nat
type family
(m :: Nat) :+ (n :: Nat) :: Nat
where
Z :+ n = n
(S k) :+ n = S (k :+ n)
-- Vec a m -> Vec a n -> Vec a (m :+ n)
GADTs
Generalized Algebraic Data Types
data Vec :: Nat -> * -> *
Nil :: Vec Z a
(:>) :: a -> Vec n a -> Vec (S n) a
data Vec (n :: Nat) (a :: *) :: * where
Nil :: n ~ Z => Nil n a
(:>) :: forall (m :: Nat)
. n ~ S m
=> a -> Vec m a -> Vec n a
tail :: Vec (S k) a -> Vec k a
tail (_ :> xs) = xs
-- (m :: Nat) (S k ~ S m)
type family
(v :: Vec a m) :++ (w :: Vec a n) :: Vec a k
where
Nil :++ w = w
(x :> xs) :++ w = x :> (xs :++ w)
type family
(v :: Vec a m) :++ (w :: Vec a n) :: Vec a k
where
Nil :++ w = w
(x :> xs) :++ w = x :> (xs :++ w)
‘Vec’ of kind ‘* -> Nat -> *’ is not promotable
In the kind ‘Vec a m’
Vec :: □ -> □ -> □
replicate :: pi (n :: Nat) -> a -> Vec a n
replicate Z a = Nil
replicate (S m) a = a :> replicate m a
data Nat = Z | S Nat
data Nat's :: Nat -> * where
Z's :: Nat's Z
S's :: Nat's n -> Nat's (S n)
-- S's Z's :: Nat's (S Z)
replicate :: Nat's n -> a -> Vec a n
replicate Z's a = Nil
replicate (S's m) a = a :> replicate m a
Они уже здесь!
Singleton types here
Singleton types there
Singleton types everywhere
Monnier & Haguenauer, 2009
Hasochism
Lindley & mcBride, 2013
data Fin :: Nat -> * where
FZ :: Fin (S n)
FS :: Fin n -> Fin (S n)
lookup :: pi (f :: Fin n) -> Vec a n -> a
lookup FZ (x :> _) = x
lookup (FS i) (_ :> xs) = lookup i xs
data Fin's (n :: Nat) (f :: Fin n) :: * where
FZ's :: Fin's (S m) FZ
FS's :: Fin's m g -> Fin's (S m) (FS g)
-- FS's FZ's :: Fin's 4 (FS FZ :: Fin 4)
data Fin's (n :: Nat) (f :: Fin n) :: * where
FZ's :: Fin's (S m) FZ
FS's :: Fin's m g -> Fin's (S m) (FS g)
Kind variable also used as type variable: ‘n’
In the data type declaration for ‘Fin's’
get "/Contract/:id" $ do
intParam "id" >>= queryDb "Contract" >>= json
type API
= "Contract"
:> Capture "id" Int
:> Get '[JSON] Contract
type Api
= "Contract"
:> Capture "id" Int
:> RoleFilter "Contract" "owner" '[43, 265]
:> Get '[JSON] (Obj Contract)
data User (fieldName :: Symbol) where
Id :: Int -> User "id"
Name :: Text -> User "name"
Roles :: [Vector (Ref Role)] -> User "roles"
data Contract (fieldName :: Symbol) where
Id :: Int -> Contract "id"
Owner :: Ref Role -> Contract "owner"
type family TableName (m :: Symbol -> *) :: Symbol
type instance TableName User = "User"
type instance TableName Contract = "Contract"
type Api
= "Contract"
:> Capture "id" Int
:> RoleFilter "Contract" "owner" '[43, 265]
:> Get '[JSON] (Obj Contract)
type Api
= MkFilter Contract
(RoleFilter C.Owner '[Role1, Role2])
type family MkFilter
(f :: Symbol)
(m :: Symbol -> *)
(filter :: *)
where
MkFilter f m (RoleFilter (own :: m g) rs)
= TableName m
:> Capture
(FieldName (TableId m))
(FieldType (TableId m))
:> RoleFilter' (TableName m) g rs
:> Get '[JSON] (Obj m)
Termination
Equality
Consistency
System FC with Explicit Kind Equality, 2013
Dependent Types in Haskell, draft
Type Inference, Haskell and Dependent Types, 2013
Stephanie Weirich
Richard A. Eisenberg
Per Martin-Löf, Intuitionistic type theory (1984)
F O R M L   M T H O D S
A
E
Зависимые типы в GHC 8. Максим Талдыкин

More Related Content

What's hot

Programming Language: Ruby
Programming Language: RubyProgramming Language: Ruby
Programming Language: Ruby
Hesham Shabana
 
JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervoso
Luis Vendrame
 
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
Dr. Volkan OBAN
 
Litebox
LiteboxLitebox
Litebox
meli media
 
Having fun with graphs, a short introduction to D3.js
Having fun with graphs, a short introduction to D3.jsHaving fun with graphs, a short introduction to D3.js
Having fun with graphs, a short introduction to D3.js
Michael Hackstein
 
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
Leo Hernandez
 
Short intro to the Rust language
Short intro to the Rust languageShort intro to the Rust language
Short intro to the Rust language
Gines Espada
 
Swift - Krzysztof Skarupa
Swift -  Krzysztof SkarupaSwift -  Krzysztof Skarupa
Swift - Krzysztof Skarupa
Sunscrapers
 
C++totural file
C++totural fileC++totural file
C++totural filehalaisumit
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2goMoriyoshi Koizumi
 
#RuPostgresLive 4: как писать и читать сложные SQL-запросы
#RuPostgresLive 4: как писать и читать сложные SQL-запросы#RuPostgresLive 4: как писать и читать сложные SQL-запросы
#RuPostgresLive 4: как писать и читать сложные SQL-запросы
Nikolay Samokhvalov
 
Class & sub class
Class & sub classClass & sub class
Class & sub class
HSS-Software House
 
刘平川:【用户行为分析】Marmot实践
刘平川:【用户行为分析】Marmot实践刘平川:【用户行为分析】Marmot实践
刘平川:【用户行为分析】Marmot实践taobao.com
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changeshayato
 
cocos2d 事例編 HungryMasterの実装から
cocos2d 事例編 HungryMasterの実装からcocos2d 事例編 HungryMasterの実装から
cocos2d 事例編 HungryMasterの実装からYuichi Higuchi
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 

What's hot (19)

Programming Language: Ruby
Programming Language: RubyProgramming Language: Ruby
Programming Language: Ruby
 
JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervoso
 
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
 
Litebox
LiteboxLitebox
Litebox
 
Having fun with graphs, a short introduction to D3.js
Having fun with graphs, a short introduction to D3.jsHaving fun with graphs, a short introduction to D3.js
Having fun with graphs, a short introduction to D3.js
 
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
 
MongoDB Oplog入門
MongoDB Oplog入門MongoDB Oplog入門
MongoDB Oplog入門
 
Short intro to the Rust language
Short intro to the Rust languageShort intro to the Rust language
Short intro to the Rust language
 
Swift - Krzysztof Skarupa
Swift -  Krzysztof SkarupaSwift -  Krzysztof Skarupa
Swift - Krzysztof Skarupa
 
Lab 13
Lab 13Lab 13
Lab 13
 
C++totural file
C++totural fileC++totural file
C++totural file
 
C++ tutorial
C++ tutorialC++ tutorial
C++ tutorial
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
 
#RuPostgresLive 4: как писать и читать сложные SQL-запросы
#RuPostgresLive 4: как писать и читать сложные SQL-запросы#RuPostgresLive 4: как писать и читать сложные SQL-запросы
#RuPostgresLive 4: как писать и читать сложные SQL-запросы
 
Class & sub class
Class & sub classClass & sub class
Class & sub class
 
刘平川:【用户行为分析】Marmot实践
刘平川:【用户行为分析】Marmot实践刘平川:【用户行为分析】Marmot实践
刘平川:【用户行为分析】Marmot实践
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changes
 
cocos2d 事例編 HungryMasterの実装から
cocos2d 事例編 HungryMasterの実装からcocos2d 事例編 HungryMasterの実装から
cocos2d 事例編 HungryMasterの実装から
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 

Viewers also liked

Краткий экскурс в системы типов или как избежать дезинтеграции. Денис Редозубов
Краткий экскурс в системы типов или как избежать дезинтеграции. Денис РедозубовКраткий экскурс в системы типов или как избежать дезинтеграции. Денис Редозубов
Краткий экскурс в системы типов или как избежать дезинтеграции. Денис Редозубов
Юрий Сыровецкий
 
Евгений Котельников. Зависимые типы в Haskell
Евгений Котельников. Зависимые типы в HaskellЕвгений Котельников. Зависимые типы в Haskell
Евгений Котельников. Зависимые типы в Haskell
FProg
 
Возможности и проблемы FFI в Haskell. Александр Вершилов
Возможности и проблемы FFI в Haskell. Александр ВершиловВозможности и проблемы FFI в Haskell. Александр Вершилов
Возможности и проблемы FFI в Haskell. Александр Вершилов
Юрий Сыровецкий
 
Fast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaFast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible Java
Charles Nutter
 
Монады для барабанщиков. Антон Холомьёв
Монады для барабанщиков. Антон ХоломьёвМонады для барабанщиков. Антон Холомьёв
Монады для барабанщиков. Антон Холомьёв
Юрий Сыровецкий
 
Cloud Haskell. Александр Вершилов
Cloud Haskell. Александр ВершиловCloud Haskell. Александр Вершилов
Cloud Haskell. Александр Вершилов
Юрий Сыровецкий
 
Ленивые вычисления: плюсы и минусы. Денис Шевченко
Ленивые вычисления: плюсы и минусы. Денис ШевченкоЛенивые вычисления: плюсы и минусы. Денис Шевченко
Ленивые вычисления: плюсы и минусы. Денис Шевченко
Юрий Сыровецкий
 
SREcon 2016 Performance Checklists for SREs
SREcon 2016 Performance Checklists for SREsSREcon 2016 Performance Checklists for SREs
SREcon 2016 Performance Checklists for SREs
Brendan Gregg
 
Анонимные записи в Haskell. Никита Волков
Анонимные записи в Haskell. Никита ВолковАнонимные записи в Haskell. Никита Волков
Анонимные записи в Haskell. Никита Волков
Юрий Сыровецкий
 

Viewers also liked (9)

Краткий экскурс в системы типов или как избежать дезинтеграции. Денис Редозубов
Краткий экскурс в системы типов или как избежать дезинтеграции. Денис РедозубовКраткий экскурс в системы типов или как избежать дезинтеграции. Денис Редозубов
Краткий экскурс в системы типов или как избежать дезинтеграции. Денис Редозубов
 
Евгений Котельников. Зависимые типы в Haskell
Евгений Котельников. Зависимые типы в HaskellЕвгений Котельников. Зависимые типы в Haskell
Евгений Котельников. Зависимые типы в Haskell
 
Возможности и проблемы FFI в Haskell. Александр Вершилов
Возможности и проблемы FFI в Haskell. Александр ВершиловВозможности и проблемы FFI в Haskell. Александр Вершилов
Возможности и проблемы FFI в Haskell. Александр Вершилов
 
Fast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaFast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible Java
 
Монады для барабанщиков. Антон Холомьёв
Монады для барабанщиков. Антон ХоломьёвМонады для барабанщиков. Антон Холомьёв
Монады для барабанщиков. Антон Холомьёв
 
Cloud Haskell. Александр Вершилов
Cloud Haskell. Александр ВершиловCloud Haskell. Александр Вершилов
Cloud Haskell. Александр Вершилов
 
Ленивые вычисления: плюсы и минусы. Денис Шевченко
Ленивые вычисления: плюсы и минусы. Денис ШевченкоЛенивые вычисления: плюсы и минусы. Денис Шевченко
Ленивые вычисления: плюсы и минусы. Денис Шевченко
 
SREcon 2016 Performance Checklists for SREs
SREcon 2016 Performance Checklists for SREsSREcon 2016 Performance Checklists for SREs
SREcon 2016 Performance Checklists for SREs
 
Анонимные записи в Haskell. Никита Волков
Анонимные записи в Haskell. Никита ВолковАнонимные записи в Haskell. Никита Волков
Анонимные записи в Haskell. Никита Волков
 

Similar to Зависимые типы в GHC 8. Максим Талдыкин

Oh Composable World!
Oh Composable World!Oh Composable World!
Oh Composable World!
Brian Lonsdorf
 
SATySFiのこれからの課題たち
SATySFiのこれからの課題たちSATySFiのこれからの課題たち
SATySFiのこれからの課題たち
T. Suwa
 
Артём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data AnalysisАртём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data Analysis
SpbDotNet Community
 
Intro To Agda
Intro To AgdaIntro To Agda
Intro To Agda
Larry Diehl
 
Some Examples in R- [Data Visualization--R graphics]
 Some Examples in R- [Data Visualization--R graphics] Some Examples in R- [Data Visualization--R graphics]
Some Examples in R- [Data Visualization--R graphics]
Dr. Volkan OBAN
 
The Essence of the Iterator Pattern (pdf)
The Essence of the Iterator Pattern (pdf)The Essence of the Iterator Pattern (pdf)
The Essence of the Iterator Pattern (pdf)
Eric Torreborre
 
Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)stasimus
 
Sigma type
Sigma typeSigma type
Sigma type
Dmytro Mitin
 
13 - Scala. Dependent pair type (Σ-type)
13 - Scala. Dependent pair type (Σ-type)13 - Scala. Dependent pair type (Σ-type)
13 - Scala. Dependent pair type (Σ-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 vectors
Roman Brovko
 
The Essence of the Iterator Pattern
The Essence of the Iterator PatternThe Essence of the Iterator Pattern
The Essence of the Iterator Pattern
Eric Torreborre
 
10. R getting spatial
10.  R getting spatial10.  R getting spatial
10. R getting spatial
ExternalEvents
 
JSDC 2014 - functional java script, why or why not
JSDC 2014 - functional java script, why or why notJSDC 2014 - functional java script, why or why not
JSDC 2014 - functional java script, why or why not
ChengHui Weng
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)MongoSF
 
Munihac 2018 - Beautiful Template Haskell
Munihac 2018 - Beautiful Template HaskellMunihac 2018 - Beautiful Template Haskell
Munihac 2018 - Beautiful Template Haskell
Matthew Pickering
 
Class Customization and Better Code
Class Customization and Better CodeClass Customization and Better Code
Class Customization and Better CodeStronnics
 
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
Mozaic Works
 
Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with Statix
Eelco Visser
 
Implementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 reduxImplementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 redux
Eleanor McHugh
 
R getting spatial
R getting spatialR getting spatial
R getting spatial
FAO
 

Similar to Зависимые типы в GHC 8. Максим Талдыкин (20)

Oh Composable World!
Oh Composable World!Oh Composable World!
Oh Composable World!
 
SATySFiのこれからの課題たち
SATySFiのこれからの課題たちSATySFiのこれからの課題たち
SATySFiのこれからの課題たち
 
Артём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data AnalysisАртём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data Analysis
 
Intro To Agda
Intro To AgdaIntro To Agda
Intro To Agda
 
Some Examples in R- [Data Visualization--R graphics]
 Some Examples in R- [Data Visualization--R graphics] Some Examples in R- [Data Visualization--R graphics]
Some Examples in R- [Data Visualization--R graphics]
 
The Essence of the Iterator Pattern (pdf)
The Essence of the Iterator Pattern (pdf)The Essence of the Iterator Pattern (pdf)
The Essence of the Iterator Pattern (pdf)
 
Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)
 
Sigma type
Sigma typeSigma type
Sigma type
 
13 - Scala. Dependent pair type (Σ-type)
13 - Scala. Dependent pair type (Σ-type)13 - Scala. Dependent pair type (Σ-type)
13 - Scala. Dependent pair type (Σ-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
 
The Essence of the Iterator Pattern
The Essence of the Iterator PatternThe Essence of the Iterator Pattern
The Essence of the Iterator Pattern
 
10. R getting spatial
10.  R getting spatial10.  R getting spatial
10. R getting spatial
 
JSDC 2014 - functional java script, why or why not
JSDC 2014 - functional java script, why or why notJSDC 2014 - functional java script, why or why not
JSDC 2014 - functional java script, why or why not
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
 
Munihac 2018 - Beautiful Template Haskell
Munihac 2018 - Beautiful Template HaskellMunihac 2018 - Beautiful Template Haskell
Munihac 2018 - Beautiful Template Haskell
 
Class Customization and Better Code
Class Customization and Better CodeClass Customization and Better Code
Class Customization and Better Code
 
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
 
Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with Statix
 
Implementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 reduxImplementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 redux
 
R getting spatial
R getting spatialR getting spatial
R getting spatial
 

Recently uploaded

Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
Globus
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 

Recently uploaded (20)

Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 

Зависимые типы в GHC 8. Максим Талдыкин

  • 1. Зависимые типы в GHC 8 Максим Талдыкин max@formalmethods.ru
  • 2.
  • 4. Just 1 : Maybe Int : * : □ Maybe : * -> * : □ Vec Int Z : * : □ Vec : * -> Nat -> * : □
  • 5. map : forall a b. (a -> b) -> [a] -> [b] map f (x:xs) = f x : map f xs map f [] = []
  • 6. map :: forall a b. (a -> b) -> [a] -> [b] map = (@a) (@b) (f :: a -> b) (ds :: [a]) -> case ds of [] -> GHC.Types.[] @b : x xs -> GHC.Types.: @b (f x) (map @a @b f xs)
  • 7. forall (a :: *) (b :: *) (f :: a -> b) (xs :: [a]) . [b]
  • 8. replicate :: pi (n : Nat) -> a -> Vec a n replicate Z _ = Nil replicate (S m) x = x :> replicate m a
  • 9. vis dep rel forall (a : *). a - + - a -> a + - + Monad m => m a - - + pi (a : Bool). f a - + + pi (a : Bool) -> f a + + +
  • 13. strncpy :: forall (p q :: Nat) => (LE n p ~ True, LE n q ~ True) . pi (n :: Nat) -> Ptr Char p -> Ptr Char q -> IO ()
  • 14. Π-Ware: Hardware Description Swierstra et al., 2015 Correct-by-Construction Concurrency Brady & Hammond, 2009 Security-Typed Programming Morgenstern & Licata, 2010
  • 16. data Nat = Z | S Nat type family (m :: Nat) :+ (n :: Nat) :: Nat where Z :+ n = n (S k) :+ n = S (k :+ n) -- Vec a m -> Vec a n -> Vec a (m :+ n)
  • 18. data Vec :: Nat -> * -> * Nil :: Vec Z a (:>) :: a -> Vec n a -> Vec (S n) a
  • 19. data Vec (n :: Nat) (a :: *) :: * where Nil :: n ~ Z => Nil n a (:>) :: forall (m :: Nat) . n ~ S m => a -> Vec m a -> Vec n a
  • 20. tail :: Vec (S k) a -> Vec k a tail (_ :> xs) = xs -- (m :: Nat) (S k ~ S m)
  • 21. type family (v :: Vec a m) :++ (w :: Vec a n) :: Vec a k where Nil :++ w = w (x :> xs) :++ w = x :> (xs :++ w)
  • 22. type family (v :: Vec a m) :++ (w :: Vec a n) :: Vec a k where Nil :++ w = w (x :> xs) :++ w = x :> (xs :++ w) ‘Vec’ of kind ‘* -> Nat -> *’ is not promotable In the kind ‘Vec a m’
  • 23. Vec :: □ -> □ -> □
  • 24. replicate :: pi (n :: Nat) -> a -> Vec a n replicate Z a = Nil replicate (S m) a = a :> replicate m a
  • 25. data Nat = Z | S Nat data Nat's :: Nat -> * where Z's :: Nat's Z S's :: Nat's n -> Nat's (S n) -- S's Z's :: Nat's (S Z)
  • 26. replicate :: Nat's n -> a -> Vec a n replicate Z's a = Nil replicate (S's m) a = a :> replicate m a
  • 28. Singleton types here Singleton types there Singleton types everywhere Monnier & Haguenauer, 2009
  • 30. data Fin :: Nat -> * where FZ :: Fin (S n) FS :: Fin n -> Fin (S n)
  • 31. lookup :: pi (f :: Fin n) -> Vec a n -> a lookup FZ (x :> _) = x lookup (FS i) (_ :> xs) = lookup i xs
  • 32. data Fin's (n :: Nat) (f :: Fin n) :: * where FZ's :: Fin's (S m) FZ FS's :: Fin's m g -> Fin's (S m) (FS g) -- FS's FZ's :: Fin's 4 (FS FZ :: Fin 4)
  • 33. data Fin's (n :: Nat) (f :: Fin n) :: * where FZ's :: Fin's (S m) FZ FS's :: Fin's m g -> Fin's (S m) (FS g) Kind variable also used as type variable: ‘n’ In the data type declaration for ‘Fin's’
  • 34. get "/Contract/:id" $ do intParam "id" >>= queryDb "Contract" >>= json type API = "Contract" :> Capture "id" Int :> Get '[JSON] Contract
  • 35. type Api = "Contract" :> Capture "id" Int :> RoleFilter "Contract" "owner" '[43, 265] :> Get '[JSON] (Obj Contract)
  • 36. data User (fieldName :: Symbol) where Id :: Int -> User "id" Name :: Text -> User "name" Roles :: [Vector (Ref Role)] -> User "roles" data Contract (fieldName :: Symbol) where Id :: Int -> Contract "id" Owner :: Ref Role -> Contract "owner" type family TableName (m :: Symbol -> *) :: Symbol type instance TableName User = "User" type instance TableName Contract = "Contract"
  • 37. type Api = "Contract" :> Capture "id" Int :> RoleFilter "Contract" "owner" '[43, 265] :> Get '[JSON] (Obj Contract) type Api = MkFilter Contract (RoleFilter C.Owner '[Role1, Role2])
  • 38. type family MkFilter (f :: Symbol) (m :: Symbol -> *) (filter :: *) where MkFilter f m (RoleFilter (own :: m g) rs) = TableName m :> Capture (FieldName (TableId m)) (FieldType (TableId m)) :> RoleFilter' (TableName m) g rs :> Get '[JSON] (Obj m)
  • 40. System FC with Explicit Kind Equality, 2013 Dependent Types in Haskell, draft Type Inference, Haskell and Dependent Types, 2013
  • 43. Per Martin-Löf, Intuitionistic type theory (1984)
  • 44. F O R M L   M T H O D S A E