SlideShare a Scribd company logo
1 of 58
Download to read offline
Row-based type systems 

for algebraic effect handlers
Taro Sekiyama

Twitter: @skymountain_
1
Contents
1. Background: algebraic effects and handlers

2. Effect-and-type systems for effect handlers
!2
Algebraic effects & handlers
[Plotkin & Pretnar ’09, ’13]
• A mechanism to give user-defined effects

(a.k.a. to use continuations in a “well-structured” manner)

• Separating interfaces and implementations 

of effects

• Invoked via operations

• Interpreted by handlers
• Handlers give the ability to call continuations
• Implemented as libraries or primitives in
languages such as Eff, Koka, Frank, etc.
!3
Example
effect fail : str ! unit
let div (x:int) (y:int) =

if y = 0 then (#fail “div0”; -1)

else x / y
let f (x:int) : (str,int) either =

handle (div 42 x) with

return (y:int) ! Right y

fail (y:str) ! Left y
!4
Example
effect fail : str ! unit
let div (x:int) (y:int) =

if y = 0 then (#fail “div0”; -1)

else x / y
let f (x:int) : (str,int) either =

handle (div 42 x) with

return (y:int) ! Right y

fail (y:str) ! Left y
Declare fail operation
!5
Example
effect fail : str ! unit
let div (x:int) (y:int) =

if y = 0 then (#fail “div0”; -1)

else x / y
let f (x:int) : (str,int) either =

handle (div 42 x) with

return (y:int) ! Right y

fail (y:str) ! Left y
Declare fail operation
Invoke fail
!6
Example
effect fail : str ! unit
let div (x:int) (y:int) =

if y = 0 then (#fail “div0”; -1)

else x / y
let f (x:int) : (str,int) either =

handle (div 42 x) with

return (y:int) ! Right y

fail (y:str) ! Left y
Declare fail operation
Invoke fail
Inject interpretation into effects
invoked in “div 42 x”
!7
Example
effect fail : str ! unit
let div (x:int) (y:int) =

if y = 0 then (#fail “div0”; -1)

else x / y
let f (x:int) : (str,int) either =

handle (div 42 x) with

return (y:int) ! Right y

fail (y:str) ! Left y
Declare fail operation
Invoke fail
Inject interpretation into effects
invoked in “div 42 x”
Interpretation of
fail operation
!8
Example
effect fail : str ! unit
let div (x:int) (y:int) =

if y = 0 then (#fail “div0”; -1)

else x / y
let f (x:int) : (str,int) either =

handle (div 42 x) with

return (y:int) ! Right y

fail (y:str) ! Left y
Declare fail operation
Invoke fail
Inject interpretation into effects
invoked in “div 42 x”
f 0 Left “div0”⟶
Interpretation of
fail operation
!8
Example
effect fail : str ! unit
let div (x:int) (y:int) =

if y = 0 then (#fail “div0”; -1)

else x / y
let f (x:int) : (str,int) either =

handle (div 42 x) with

return (y:int) ! Right y

fail (y:str) ! Left y
Declare fail operation
Invoke fail
f 0 Left “div0”⟶
Inject interpretation into effects
invoked in “div 42 x”
Evaluated with

the value of “div 42 x”
Interpretation of
fail operation
!9
Example
effect fail : str ! unit
let div (x:int) (y:int) =

if y = 0 then (#fail “div0”; -1)

else x / y
let f (x:int) : (str,int) either =

handle (div 42 x) with

return (y:int) ! Right y

fail (y:str) ! Left y
Declare fail operation
Invoke fail
f 7 Right 6⟶f 0 Left “div0”⟶
Inject interpretation into effects
invoked in “div 42 x”
Evaluated with

the value of “div 42 x”
Interpretation of
fail operation
!9
Resumption
Handlers support resumption of the computation
from the point of the effect invocation

• Reminiscent of delimited continuation
effect choose : int × int ! int
handle #choose(1,2) + 

#choose(10,20) with

return (x:int) ! x

choose (x:int,y:int) ! resume x
!10
Resumption
Handlers support resumption of the computation
from the point of the effect invocation

• Reminiscent of delimited continuation
effect choose : int × int ! int
handle #choose(1,2) + 

#choose(10,20) with

return (x:int) ! x

choose (x:int,y:int) ! resume x
!10
Resumption
Handlers support resumption of the computation
from the point of the effect invocation

• Reminiscent of delimited continuation
effect choose : int × int ! int
handle #choose(1,2) + 

#choose(10,20) with

return (x:int) ! x

choose (x:int,y:int) ! resume x
!10
Resumption
Handlers support resumption of the computation
from the point of the effect invocation

• Reminiscent of delimited continuation
effect choose : int × int ! int
handle #choose(1,2) + 

#choose(10,20) with

return (x:int) ! x

choose (x:int,y:int) ! resume x
Return x as 

the result of #choose
!11
Resumption
Handlers support resumption of the computation
from the point of the effect invocation

• Reminiscent of delimited continuation
effect choose : int × int ! int
handle #choose(1,2) + 

#choose(10,20) with

return (x:int) ! x

choose (x:int,y:int) ! resume x
Return x as 

the result of #choose
!11
Resumption
Handlers support resumption of the computation
from the point of the effect invocation

• Reminiscent of delimited continuation
effect choose : int × int ! int
handle #choose(1,2) + 

#choose(10,20) with

return (x:int) ! x

choose (x:int,y:int) ! resume x
x := 1
Return x as 

the result of #choose
!11
Resumption
Handlers support resumption of the computation
from the point of the effect invocation

• Reminiscent of delimited continuation
effect choose : int × int ! int
handle 1 + 

#choose(10,20) with

return (x:int) ! x

choose (x:int,y:int) ! resume x
x := 1
Return x as 

the result of #choose
!12
Resumption
Handlers support resumption of the computation
from the point of the effect invocation

• Reminiscent of delimited continuation
effect choose : int × int ! int
handle 1 + 

#choose(10,20) with

return (x:int) ! x

choose (x:int,y:int) ! resume x
Return x as 

the result of #choose
!13
Resumption
Handlers support resumption of the computation
from the point of the effect invocation

• Reminiscent of delimited continuation
effect choose : int × int ! int
handle 1 + 

#choose(10,20) with

return (x:int) ! x

choose (x:int,y:int) ! resume x
Return x as 

the result of #choose
!13
Resumption
effect choose : int × int ! int
handle 1 + 

10 with

return (x:int) ! x

choose (x:int,y:int) ! resume x
Handlers support resumption of the computation
from the point of the effect invocation

• Reminiscent of delimited continuation
Return x as 

the result of #choose
!14
Parameterized effects
effect α choose : α × α ! α
handle if #choose(true,false)

then 1 else 2 with

return (x:int) ! #choose(10,20) + x

bool choose (x,y) ! resume (x && y)
!15
Parameterized effects
effect α choose : α × α ! α
handle if #choose(true,false)

then 1 else 2 with

return (x:int) ! #choose(10,20) + x

bool choose (x,y) ! resume (x && y)
!16
Signature is parameterized over types
Parameterized effects
effect α choose : α × α ! α
handle if #choose(true,false)

then 1 else 2 with

return (x:int) ! #choose(10,20) + x

bool choose (x,y) ! resume (x && y)
!17
Signature is parameterized over types
α := bool
Parameterized effects
effect α choose : α × α ! α
handle if #choose(true,false)

then 1 else 2 with

return (x:int) ! #choose(10,20) + x

bool choose (x,y) ! resume (x && y)
!18
Signature is parameterized over types
α := bool
Effect “bool choose” is handled
Parameterized effects
effect α choose : α × α ! α
handle if #choose(true,false)

then 1 else 2 with

return (x:int) ! #choose(10,20) + x

bool choose (x,y) ! resume (x && y)
!19
Signature is parameterized over types
α := bool
α := int
Effect “bool choose” is handled
Parameterized effects
effect α choose : α × α ! α
handle if #choose(true,false)

then 1 else 2 with

return (x:int) ! #choose(10,20) + x

bool choose (x,y) ! resume (x && y)
!19
Effect “int choose” will be
handled by an outer handler
Signature is parameterized over types
α := bool
α := int
Effect “bool choose” is handled
Contents
1. Background: algebraic effects and handlers

2. Effect-and-type systems for effect handlers
!20
Motivation
Detection of “Handler-Not-Found” error
!21
effect fail : str ! unit
let div (x:int) (y:int) =

if y = 0 then (#fail “div0”; -1)

else x / y
div 10 0
Motivation
Detection of “Handler-Not-Found” error
!21
effect fail : str ! unit
let div (x:int) (y:int) =

if y = 0 then (#fail “div0”; -1)

else x / y
div 10 0
There are no
handlers for #fail
Effect(-and-type) system
A means to detect invoked effects statically

• Types contain information about effects
!22
τ1 ! τ2Function type
Effect(-and-type) system
A means to detect invoked effects statically

• Types contain information about effects
!22
τ1 ! τ2Function type ε
Functions of this type may invoke effects ε
Row-based effect system

[Hillerström+ ’16; Leijen ’17; Lindley+ 17]
Effects ε are represented by a row
• It is originated from record typing

• Supported by Koka, Frank, Links, etc.
!23
Row-based effect system

[Hillerström+ ’16; Leijen ’17; Lindley+ 17]
Effects ε are represented by a row
• It is originated from record typing

• Supported by Koka, Frank, Links, etc.
!23
A sequence of effect names

〈 fail, int choose, … 〉
Row-based effect system

[Hillerström+ ’16; Leijen ’17; Lindley+ 17]
Effects ε are represented by a row
• It is originated from record typing

• Supported by Koka, Frank, Links, etc.
!23
A sequence of effect names

〈 fail, int choose, … 〉
τ1 !〈fail, int choose〉τ2
Row-based effect system

[Hillerström+ ’16; Leijen ’17; Lindley+ 17]
Effects ε are represented by a row
• It is originated from record typing

• Supported by Koka, Frank, Links, etc.
!23
A sequence of effect names

〈 fail, int choose, … 〉
Given to functions that may invoke
only “fail" and/or “int choose”
τ1 !〈fail, int choose〉τ2
Example
effect fail : str ! unit
let div (x:int) (y:int) =

if y = 0 then (#fail “div0”; -1)

else x / y
!24
let f (x:int) : (str,int) either =

handle (div 42 x) with

return (y:int) ! Right y

fail (y:str) ! Left y
Example
effect fail : str ! unit
let div (x:int) (y:int) =

if y = 0 then (#fail “div0”; -1)

else x / y
!24
div : int !〈〉int !〈fail〉int
let f (x:int) : (str,int) either =

handle (div 42 x) with

return (y:int) ! Right y

fail (y:str) ! Left y
Example
effect fail : str ! unit
let div (x:int) (y:int) =

if y = 0 then (#fail “div0”; -1)

else x / y
!24
div : int !〈〉int !〈fail〉int
let f (x:int) : (str,int) either =

handle (div 42 x) with

return (y:int) ! Right y

fail (y:str) ! Left y
f : int !〈〉(str, int) either
Features
1. Parametric effects by row polymorphism

2. Duplication of effect names
!25
Features
1. Parametric effects by row polymorphism
2. Duplication of effect names
!26
Example
!27
effect fail : str ! unit
type α opt = Some of α | None
let to-maybe (f : unit !〈fail〉α) : α opt =

handle f () with

return x ! Some x

fail _ ! None
to-maybe : ∀α. (unit !〈fail〉α) !〈〉α opt
Example
!27
effect fail : str ! unit
type α opt = Some of α | None
let to-maybe (f : unit !〈fail〉α) : α opt =

handle f () with

return x ! Some x

fail _ ! None
Problem: to-maybe cannot be applied to
functions invoking effects other than fail
Ex: to-maybe (fun () ! #choose(1,2))
to-maybe : ∀α. (unit !〈fail〉α) !〈〉α opt
Row polymorphism
Allowing functions to be parameterized over rows
!28
effect fail : str ! unit
let to-maybe (f : unit !〈fail, ρ〉α) =

handle f () with

return x ! Some x

fail _ ! None
Row polymorphism
Allowing functions to be parameterized over rows
!28
effect fail : str ! unit
let to-maybe (f : unit !〈fail, ρ〉α) =

handle f () with

return x ! Some x

fail _ ! None
Row variable
f will invoke fail and/or
effects substituted for ρ
Row polymorphism
Allowing functions to be parameterized over rows
!28
effect fail : str ! unit
let to-maybe (f : unit !〈fail, ρ〉α) =

handle f () with

return x ! Some x

fail _ ! None
∀α,ρ. (unit !〈fail,ρ〉α) !〈ρ〉α opt
to-maybe (fun () ! #choose(1,2))

by instantiating ρ with〈int choose〉
Row variable
f will invoke fail and/or
effects substituted for ρ
Distinctive features
1. Parametric effects by row polymorphism

2. Duplication of effect names
!29
Duplication of effect names
• An effect can occur in multiple positions in a row

• Multiple parameterized effects with the same
name can occur in a row
!30
〈fail, int choose, fail〉
〈fail, int choose, bool choose〉
Benefits of duplication
• Functions can invoke effects given different
type parameters

• Simplifying the effect system, especially, with
row polymorphism

• Support for abstract effects
!31
Benefits of duplication
• Functions can invoke effects given different
type parameters
• Simplifying the effect system, especially, with
row polymorphism

• Support for abstract effects
!32
Benefit 1
Functions can invoke effects given different type
parameters
!33
let f () =

if #choose(true, false)

then #choose(1, 2) 

else #choose(10, 20)
Benefit 1
Functions can invoke effects given different type
parameters
!33
let f () =

if #choose(true, false)

then #choose(1, 2) 

else #choose(10, 20)
bool choose
Benefit 1
Functions can invoke effects given different type
parameters
!33
let f () =

if #choose(true, false)

then #choose(1, 2) 

else #choose(10, 20)
bool choose
Int chooseint choose
Benefit 1
Functions can invoke effects given different type
parameters
!33
let f () =

if #choose(true, false)

then #choose(1, 2) 

else #choose(10, 20)
bool choose
Int chooseint choose
f : unit !〈bool choose, int choose〉int
Handling duplicated effects
Effects are handled from the leftmost among
ones having the same name
!34
let f

(g : unit !〈int choose, bool choose〉unit) =

handle g () with

return x ! 0

int choose (x,y) ! 1
Handling duplicated effects
Effects are handled from the leftmost among
ones having the same name
!35
let f

(g : unit !〈int choose, bool choose〉unit) =

handle g () with

return x ! 0

bool choose (x,y) ! 1
Conclusion
• Algebraic effects & handlers are a means 

to give user-defined effects

• Effect systems structure and analyze 

effectful behavior of programs

• Row-based systems are expressive and
amenable
!36
Call for collaboration
Research interests

• New effect systems to capture and structure
effectful behavior

• Efficient implementation of effect handlers

• Practical applications of effects 

(and continuations)
!37

More Related Content

What's hot

ドキュメンテーションを加速するストレスフリーの作図ツール『blockdiag』 jus2011年6月勉強会
ドキュメンテーションを加速するストレスフリーの作図ツール『blockdiag』 jus2011年6月勉強会ドキュメンテーションを加速するストレスフリーの作図ツール『blockdiag』 jus2011年6月勉強会
ドキュメンテーションを加速するストレスフリーの作図ツール『blockdiag』 jus2011年6月勉強会Takayuki Shimizukawa
 
ラムダ計算入門
ラムダ計算入門ラムダ計算入門
ラムダ計算入門Eita Sugimoto
 
リテラルと型の話 #__swift__
リテラルと型の話 #__swift__リテラルと型の話 #__swift__
リテラルと型の話 #__swift__Tomohiro Kumagai
 
Reinventing the Transaction Script (NDC London 2020)
Reinventing the Transaction Script (NDC London 2020)Reinventing the Transaction Script (NDC London 2020)
Reinventing the Transaction Script (NDC London 2020)Scott Wlaschin
 
入門Transducers
入門Transducers入門Transducers
入門Transducerssohta
 
Reactive Extensionsで非同期処理を簡単に
Reactive Extensionsで非同期処理を簡単にReactive Extensionsで非同期処理を簡単に
Reactive Extensionsで非同期処理を簡単にYoshifumi Kawai
 
"Simple Made Easy" Made Easy
"Simple Made Easy" Made Easy"Simple Made Easy" Made Easy
"Simple Made Easy" Made EasyKent Ohashi
 
ホモトピー型理論入門
ホモトピー型理論入門ホモトピー型理論入門
ホモトピー型理論入門k h
 
Functional Domain Modeling - The ZIO 2 Way
Functional Domain Modeling - The ZIO 2 WayFunctional Domain Modeling - The ZIO 2 Way
Functional Domain Modeling - The ZIO 2 WayDebasish Ghosh
 
PHPでWebSocketを実装してみてわかったこと
PHPでWebSocketを実装してみてわかったことPHPでWebSocketを実装してみてわかったこと
PHPでWebSocketを実装してみてわかったことksimoji
 
10分で分かるr言語入門ver2.10 14 1101
10分で分かるr言語入門ver2.10 14 110110分で分かるr言語入門ver2.10 14 1101
10分で分かるr言語入門ver2.10 14 1101Nobuaki Oshiro
 
Redux Saga - Under the hood
Redux Saga - Under the hoodRedux Saga - Under the hood
Redux Saga - Under the hoodWaqqas Jabbar
 
Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!Jorge Vásquez
 
Domain Driven Design with the F# type System -- F#unctional Londoners 2014
Domain Driven Design with the F# type System -- F#unctional Londoners 2014Domain Driven Design with the F# type System -- F#unctional Londoners 2014
Domain Driven Design with the F# type System -- F#unctional Londoners 2014Scott Wlaschin
 
環境構築から始めるDjangoチュートリアル
環境構築から始めるDjangoチュートリアル環境構築から始めるDjangoチュートリアル
環境構築から始めるDjangoチュートリアルsakihohoribe
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with GroovyArturo Herrero
 
.NET最先端技術によるハイパフォーマンスウェブアプリケーション
.NET最先端技術によるハイパフォーマンスウェブアプリケーション.NET最先端技術によるハイパフォーマンスウェブアプリケーション
.NET最先端技術によるハイパフォーマンスウェブアプリケーションYoshifumi Kawai
 

What's hot (20)

ドキュメンテーションを加速するストレスフリーの作図ツール『blockdiag』 jus2011年6月勉強会
ドキュメンテーションを加速するストレスフリーの作図ツール『blockdiag』 jus2011年6月勉強会ドキュメンテーションを加速するストレスフリーの作図ツール『blockdiag』 jus2011年6月勉強会
ドキュメンテーションを加速するストレスフリーの作図ツール『blockdiag』 jus2011年6月勉強会
 
ラムダ計算入門
ラムダ計算入門ラムダ計算入門
ラムダ計算入門
 
リテラルと型の話 #__swift__
リテラルと型の話 #__swift__リテラルと型の話 #__swift__
リテラルと型の話 #__swift__
 
Reinventing the Transaction Script (NDC London 2020)
Reinventing the Transaction Script (NDC London 2020)Reinventing the Transaction Script (NDC London 2020)
Reinventing the Transaction Script (NDC London 2020)
 
入門Transducers
入門Transducers入門Transducers
入門Transducers
 
Reactive Extensionsで非同期処理を簡単に
Reactive Extensionsで非同期処理を簡単にReactive Extensionsで非同期処理を簡単に
Reactive Extensionsで非同期処理を簡単に
 
"Simple Made Easy" Made Easy
"Simple Made Easy" Made Easy"Simple Made Easy" Made Easy
"Simple Made Easy" Made Easy
 
ホモトピー型理論入門
ホモトピー型理論入門ホモトピー型理論入門
ホモトピー型理論入門
 
Functional Domain Modeling - The ZIO 2 Way
Functional Domain Modeling - The ZIO 2 WayFunctional Domain Modeling - The ZIO 2 Way
Functional Domain Modeling - The ZIO 2 Way
 
PHPでWebSocketを実装してみてわかったこと
PHPでWebSocketを実装してみてわかったことPHPでWebSocketを実装してみてわかったこと
PHPでWebSocketを実装してみてわかったこと
 
Comonads in Haskell
Comonads in HaskellComonads in Haskell
Comonads in Haskell
 
10分で分かるr言語入門ver2.10 14 1101
10分で分かるr言語入門ver2.10 14 110110分で分かるr言語入門ver2.10 14 1101
10分で分かるr言語入門ver2.10 14 1101
 
Redux Saga - Under the hood
Redux Saga - Under the hoodRedux Saga - Under the hood
Redux Saga - Under the hood
 
Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!
 
Domain Driven Design with the F# type System -- F#unctional Londoners 2014
Domain Driven Design with the F# type System -- F#unctional Londoners 2014Domain Driven Design with the F# type System -- F#unctional Londoners 2014
Domain Driven Design with the F# type System -- F#unctional Londoners 2014
 
Go入門
Go入門Go入門
Go入門
 
環境構築から始めるDjangoチュートリアル
環境構築から始めるDjangoチュートリアル環境構築から始めるDjangoチュートリアル
環境構築から始めるDjangoチュートリアル
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
TDDBC お題
TDDBC お題TDDBC お題
TDDBC お題
 
.NET最先端技術によるハイパフォーマンスウェブアプリケーション
.NET最先端技術によるハイパフォーマンスウェブアプリケーション.NET最先端技術によるハイパフォーマンスウェブアプリケーション
.NET最先端技術によるハイパフォーマンスウェブアプリケーション
 

Similar to Row-based Effect Systems for Algebraic Effect Handlers

introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptxManojKhadilkar1
 
Declare Your Language: Name Resolution
Declare Your Language: Name ResolutionDeclare Your Language: Name Resolution
Declare Your Language: Name ResolutionEelco Visser
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2vikram mahendra
 
A formalization of complex event stream processing
A formalization of complex event stream processingA formalization of complex event stream processing
A formalization of complex event stream processingSylvain Hallé
 
Module II Partition and Generating Function (2).ppt
Module II Partition and Generating Function (2).pptModule II Partition and Generating Function (2).ppt
Module II Partition and Generating Function (2).pptssuser26e219
 
Lecture 3 and 4.pptx
Lecture 3 and 4.pptxLecture 3 and 4.pptx
Lecture 3 and 4.pptxMAHAMASADIK
 
FUNCTIONS IN PYTHON, CLASS 12 COMPUTER SCIENCE
FUNCTIONS IN PYTHON, CLASS 12 COMPUTER SCIENCEFUNCTIONS IN PYTHON, CLASS 12 COMPUTER SCIENCE
FUNCTIONS IN PYTHON, CLASS 12 COMPUTER SCIENCEVenugopalavarma Raja
 
FUNCTIONS IN PYTHON. CBSE +2 COMPUTER SCIENCE
FUNCTIONS IN PYTHON. CBSE +2 COMPUTER SCIENCEFUNCTIONS IN PYTHON. CBSE +2 COMPUTER SCIENCE
FUNCTIONS IN PYTHON. CBSE +2 COMPUTER SCIENCEVenugopalavarma Raja
 
High Wizardry in the Land of Scala
High Wizardry in the Land of ScalaHigh Wizardry in the Land of Scala
High Wizardry in the Land of Scaladjspiewak
 
Python-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptxPython-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptxElijahSantos4
 
Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)Rick Copeland
 
Introduction to python programming ( part-2 )
Introduction to python programming ( part-2 )Introduction to python programming ( part-2 )
Introduction to python programming ( part-2 )Ziyauddin Shaik
 
Data Handling.pdf
Data Handling.pdfData Handling.pdf
Data Handling.pdfMILANOP1
 
Tutorial on convolutional neural networks
Tutorial on convolutional neural networksTutorial on convolutional neural networks
Tutorial on convolutional neural networksHojin Yang
 
Tip Top Typing - A Look at Python Typing
Tip Top Typing - A Look at Python TypingTip Top Typing - A Look at Python Typing
Tip Top Typing - A Look at Python TypingPatrick Viafore
 

Similar to Row-based Effect Systems for Algebraic Effect Handlers (20)

introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptx
 
Declare Your Language: Name Resolution
Declare Your Language: Name ResolutionDeclare Your Language: Name Resolution
Declare Your Language: Name Resolution
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2
 
A formalization of complex event stream processing
A formalization of complex event stream processingA formalization of complex event stream processing
A formalization of complex event stream processing
 
Module II Partition and Generating Function (2).ppt
Module II Partition and Generating Function (2).pptModule II Partition and Generating Function (2).ppt
Module II Partition and Generating Function (2).ppt
 
Lecture 3 and 4.pptx
Lecture 3 and 4.pptxLecture 3 and 4.pptx
Lecture 3 and 4.pptx
 
10. Recursion
10. Recursion10. Recursion
10. Recursion
 
FUNCTIONS IN PYTHON, CLASS 12 COMPUTER SCIENCE
FUNCTIONS IN PYTHON, CLASS 12 COMPUTER SCIENCEFUNCTIONS IN PYTHON, CLASS 12 COMPUTER SCIENCE
FUNCTIONS IN PYTHON, CLASS 12 COMPUTER SCIENCE
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
 
FUNCTIONS IN PYTHON. CBSE +2 COMPUTER SCIENCE
FUNCTIONS IN PYTHON. CBSE +2 COMPUTER SCIENCEFUNCTIONS IN PYTHON. CBSE +2 COMPUTER SCIENCE
FUNCTIONS IN PYTHON. CBSE +2 COMPUTER SCIENCE
 
High Wizardry in the Land of Scala
High Wizardry in the Land of ScalaHigh Wizardry in the Land of Scala
High Wizardry in the Land of Scala
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
 
Python-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptxPython-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptx
 
Python
PythonPython
Python
 
Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)
 
Introduction to python programming ( part-2 )
Introduction to python programming ( part-2 )Introduction to python programming ( part-2 )
Introduction to python programming ( part-2 )
 
Data Handling.pdf
Data Handling.pdfData Handling.pdf
Data Handling.pdf
 
Tutorial on convolutional neural networks
Tutorial on convolutional neural networksTutorial on convolutional neural networks
Tutorial on convolutional neural networks
 
Operators
OperatorsOperators
Operators
 
Tip Top Typing - A Look at Python Typing
Tip Top Typing - A Look at Python TypingTip Top Typing - A Look at Python Typing
Tip Top Typing - A Look at Python Typing
 

Recently uploaded

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 

Recently uploaded (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

Row-based Effect Systems for Algebraic Effect Handlers

  • 1. Row-based type systems 
 for algebraic effect handlers Taro Sekiyama Twitter: @skymountain_ 1
  • 2. Contents 1. Background: algebraic effects and handlers 2. Effect-and-type systems for effect handlers !2
  • 3. Algebraic effects & handlers [Plotkin & Pretnar ’09, ’13] • A mechanism to give user-defined effects
 (a.k.a. to use continuations in a “well-structured” manner) • Separating interfaces and implementations 
 of effects • Invoked via operations • Interpreted by handlers • Handlers give the ability to call continuations • Implemented as libraries or primitives in languages such as Eff, Koka, Frank, etc. !3
  • 4. Example effect fail : str ! unit let div (x:int) (y:int) =
 if y = 0 then (#fail “div0”; -1)
 else x / y let f (x:int) : (str,int) either =
 handle (div 42 x) with
 return (y:int) ! Right y
 fail (y:str) ! Left y !4
  • 5. Example effect fail : str ! unit let div (x:int) (y:int) =
 if y = 0 then (#fail “div0”; -1)
 else x / y let f (x:int) : (str,int) either =
 handle (div 42 x) with
 return (y:int) ! Right y
 fail (y:str) ! Left y Declare fail operation !5
  • 6. Example effect fail : str ! unit let div (x:int) (y:int) =
 if y = 0 then (#fail “div0”; -1)
 else x / y let f (x:int) : (str,int) either =
 handle (div 42 x) with
 return (y:int) ! Right y
 fail (y:str) ! Left y Declare fail operation Invoke fail !6
  • 7. Example effect fail : str ! unit let div (x:int) (y:int) =
 if y = 0 then (#fail “div0”; -1)
 else x / y let f (x:int) : (str,int) either =
 handle (div 42 x) with
 return (y:int) ! Right y
 fail (y:str) ! Left y Declare fail operation Invoke fail Inject interpretation into effects invoked in “div 42 x” !7
  • 8. Example effect fail : str ! unit let div (x:int) (y:int) =
 if y = 0 then (#fail “div0”; -1)
 else x / y let f (x:int) : (str,int) either =
 handle (div 42 x) with
 return (y:int) ! Right y
 fail (y:str) ! Left y Declare fail operation Invoke fail Inject interpretation into effects invoked in “div 42 x” Interpretation of fail operation !8
  • 9. Example effect fail : str ! unit let div (x:int) (y:int) =
 if y = 0 then (#fail “div0”; -1)
 else x / y let f (x:int) : (str,int) either =
 handle (div 42 x) with
 return (y:int) ! Right y
 fail (y:str) ! Left y Declare fail operation Invoke fail Inject interpretation into effects invoked in “div 42 x” f 0 Left “div0”⟶ Interpretation of fail operation !8
  • 10. Example effect fail : str ! unit let div (x:int) (y:int) =
 if y = 0 then (#fail “div0”; -1)
 else x / y let f (x:int) : (str,int) either =
 handle (div 42 x) with
 return (y:int) ! Right y
 fail (y:str) ! Left y Declare fail operation Invoke fail f 0 Left “div0”⟶ Inject interpretation into effects invoked in “div 42 x” Evaluated with
 the value of “div 42 x” Interpretation of fail operation !9
  • 11. Example effect fail : str ! unit let div (x:int) (y:int) =
 if y = 0 then (#fail “div0”; -1)
 else x / y let f (x:int) : (str,int) either =
 handle (div 42 x) with
 return (y:int) ! Right y
 fail (y:str) ! Left y Declare fail operation Invoke fail f 7 Right 6⟶f 0 Left “div0”⟶ Inject interpretation into effects invoked in “div 42 x” Evaluated with
 the value of “div 42 x” Interpretation of fail operation !9
  • 12. Resumption Handlers support resumption of the computation from the point of the effect invocation • Reminiscent of delimited continuation effect choose : int × int ! int handle #choose(1,2) + 
 #choose(10,20) with
 return (x:int) ! x
 choose (x:int,y:int) ! resume x !10
  • 13. Resumption Handlers support resumption of the computation from the point of the effect invocation • Reminiscent of delimited continuation effect choose : int × int ! int handle #choose(1,2) + 
 #choose(10,20) with
 return (x:int) ! x
 choose (x:int,y:int) ! resume x !10
  • 14. Resumption Handlers support resumption of the computation from the point of the effect invocation • Reminiscent of delimited continuation effect choose : int × int ! int handle #choose(1,2) + 
 #choose(10,20) with
 return (x:int) ! x
 choose (x:int,y:int) ! resume x !10
  • 15. Resumption Handlers support resumption of the computation from the point of the effect invocation • Reminiscent of delimited continuation effect choose : int × int ! int handle #choose(1,2) + 
 #choose(10,20) with
 return (x:int) ! x
 choose (x:int,y:int) ! resume x Return x as 
 the result of #choose !11
  • 16. Resumption Handlers support resumption of the computation from the point of the effect invocation • Reminiscent of delimited continuation effect choose : int × int ! int handle #choose(1,2) + 
 #choose(10,20) with
 return (x:int) ! x
 choose (x:int,y:int) ! resume x Return x as 
 the result of #choose !11
  • 17. Resumption Handlers support resumption of the computation from the point of the effect invocation • Reminiscent of delimited continuation effect choose : int × int ! int handle #choose(1,2) + 
 #choose(10,20) with
 return (x:int) ! x
 choose (x:int,y:int) ! resume x x := 1 Return x as 
 the result of #choose !11
  • 18. Resumption Handlers support resumption of the computation from the point of the effect invocation • Reminiscent of delimited continuation effect choose : int × int ! int handle 1 + 
 #choose(10,20) with
 return (x:int) ! x
 choose (x:int,y:int) ! resume x x := 1 Return x as 
 the result of #choose !12
  • 19. Resumption Handlers support resumption of the computation from the point of the effect invocation • Reminiscent of delimited continuation effect choose : int × int ! int handle 1 + 
 #choose(10,20) with
 return (x:int) ! x
 choose (x:int,y:int) ! resume x Return x as 
 the result of #choose !13
  • 20. Resumption Handlers support resumption of the computation from the point of the effect invocation • Reminiscent of delimited continuation effect choose : int × int ! int handle 1 + 
 #choose(10,20) with
 return (x:int) ! x
 choose (x:int,y:int) ! resume x Return x as 
 the result of #choose !13
  • 21. Resumption effect choose : int × int ! int handle 1 + 
 10 with
 return (x:int) ! x
 choose (x:int,y:int) ! resume x Handlers support resumption of the computation from the point of the effect invocation • Reminiscent of delimited continuation Return x as 
 the result of #choose !14
  • 22. Parameterized effects effect α choose : α × α ! α handle if #choose(true,false)
 then 1 else 2 with
 return (x:int) ! #choose(10,20) + x
 bool choose (x,y) ! resume (x && y) !15
  • 23. Parameterized effects effect α choose : α × α ! α handle if #choose(true,false)
 then 1 else 2 with
 return (x:int) ! #choose(10,20) + x
 bool choose (x,y) ! resume (x && y) !16 Signature is parameterized over types
  • 24. Parameterized effects effect α choose : α × α ! α handle if #choose(true,false)
 then 1 else 2 with
 return (x:int) ! #choose(10,20) + x
 bool choose (x,y) ! resume (x && y) !17 Signature is parameterized over types α := bool
  • 25. Parameterized effects effect α choose : α × α ! α handle if #choose(true,false)
 then 1 else 2 with
 return (x:int) ! #choose(10,20) + x
 bool choose (x,y) ! resume (x && y) !18 Signature is parameterized over types α := bool Effect “bool choose” is handled
  • 26. Parameterized effects effect α choose : α × α ! α handle if #choose(true,false)
 then 1 else 2 with
 return (x:int) ! #choose(10,20) + x
 bool choose (x,y) ! resume (x && y) !19 Signature is parameterized over types α := bool α := int Effect “bool choose” is handled
  • 27. Parameterized effects effect α choose : α × α ! α handle if #choose(true,false)
 then 1 else 2 with
 return (x:int) ! #choose(10,20) + x
 bool choose (x,y) ! resume (x && y) !19 Effect “int choose” will be handled by an outer handler Signature is parameterized over types α := bool α := int Effect “bool choose” is handled
  • 28. Contents 1. Background: algebraic effects and handlers 2. Effect-and-type systems for effect handlers !20
  • 29. Motivation Detection of “Handler-Not-Found” error !21 effect fail : str ! unit let div (x:int) (y:int) =
 if y = 0 then (#fail “div0”; -1)
 else x / y div 10 0
  • 30. Motivation Detection of “Handler-Not-Found” error !21 effect fail : str ! unit let div (x:int) (y:int) =
 if y = 0 then (#fail “div0”; -1)
 else x / y div 10 0 There are no handlers for #fail
  • 31. Effect(-and-type) system A means to detect invoked effects statically • Types contain information about effects !22 τ1 ! τ2Function type
  • 32. Effect(-and-type) system A means to detect invoked effects statically • Types contain information about effects !22 τ1 ! τ2Function type ε Functions of this type may invoke effects ε
  • 33. Row-based effect system
 [Hillerström+ ’16; Leijen ’17; Lindley+ 17] Effects ε are represented by a row • It is originated from record typing • Supported by Koka, Frank, Links, etc. !23
  • 34. Row-based effect system
 [Hillerström+ ’16; Leijen ’17; Lindley+ 17] Effects ε are represented by a row • It is originated from record typing • Supported by Koka, Frank, Links, etc. !23 A sequence of effect names
 〈 fail, int choose, … 〉
  • 35. Row-based effect system
 [Hillerström+ ’16; Leijen ’17; Lindley+ 17] Effects ε are represented by a row • It is originated from record typing • Supported by Koka, Frank, Links, etc. !23 A sequence of effect names
 〈 fail, int choose, … 〉 τ1 !〈fail, int choose〉τ2
  • 36. Row-based effect system
 [Hillerström+ ’16; Leijen ’17; Lindley+ 17] Effects ε are represented by a row • It is originated from record typing • Supported by Koka, Frank, Links, etc. !23 A sequence of effect names
 〈 fail, int choose, … 〉 Given to functions that may invoke only “fail" and/or “int choose” τ1 !〈fail, int choose〉τ2
  • 37. Example effect fail : str ! unit let div (x:int) (y:int) =
 if y = 0 then (#fail “div0”; -1)
 else x / y !24 let f (x:int) : (str,int) either =
 handle (div 42 x) with
 return (y:int) ! Right y
 fail (y:str) ! Left y
  • 38. Example effect fail : str ! unit let div (x:int) (y:int) =
 if y = 0 then (#fail “div0”; -1)
 else x / y !24 div : int !〈〉int !〈fail〉int let f (x:int) : (str,int) either =
 handle (div 42 x) with
 return (y:int) ! Right y
 fail (y:str) ! Left y
  • 39. Example effect fail : str ! unit let div (x:int) (y:int) =
 if y = 0 then (#fail “div0”; -1)
 else x / y !24 div : int !〈〉int !〈fail〉int let f (x:int) : (str,int) either =
 handle (div 42 x) with
 return (y:int) ! Right y
 fail (y:str) ! Left y f : int !〈〉(str, int) either
  • 40. Features 1. Parametric effects by row polymorphism 2. Duplication of effect names !25
  • 41. Features 1. Parametric effects by row polymorphism 2. Duplication of effect names !26
  • 42. Example !27 effect fail : str ! unit type α opt = Some of α | None let to-maybe (f : unit !〈fail〉α) : α opt =
 handle f () with
 return x ! Some x
 fail _ ! None to-maybe : ∀α. (unit !〈fail〉α) !〈〉α opt
  • 43. Example !27 effect fail : str ! unit type α opt = Some of α | None let to-maybe (f : unit !〈fail〉α) : α opt =
 handle f () with
 return x ! Some x
 fail _ ! None Problem: to-maybe cannot be applied to functions invoking effects other than fail Ex: to-maybe (fun () ! #choose(1,2)) to-maybe : ∀α. (unit !〈fail〉α) !〈〉α opt
  • 44. Row polymorphism Allowing functions to be parameterized over rows !28 effect fail : str ! unit let to-maybe (f : unit !〈fail, ρ〉α) =
 handle f () with
 return x ! Some x
 fail _ ! None
  • 45. Row polymorphism Allowing functions to be parameterized over rows !28 effect fail : str ! unit let to-maybe (f : unit !〈fail, ρ〉α) =
 handle f () with
 return x ! Some x
 fail _ ! None Row variable f will invoke fail and/or effects substituted for ρ
  • 46. Row polymorphism Allowing functions to be parameterized over rows !28 effect fail : str ! unit let to-maybe (f : unit !〈fail, ρ〉α) =
 handle f () with
 return x ! Some x
 fail _ ! None ∀α,ρ. (unit !〈fail,ρ〉α) !〈ρ〉α opt to-maybe (fun () ! #choose(1,2))
 by instantiating ρ with〈int choose〉 Row variable f will invoke fail and/or effects substituted for ρ
  • 47. Distinctive features 1. Parametric effects by row polymorphism 2. Duplication of effect names !29
  • 48. Duplication of effect names • An effect can occur in multiple positions in a row • Multiple parameterized effects with the same name can occur in a row !30 〈fail, int choose, fail〉 〈fail, int choose, bool choose〉
  • 49. Benefits of duplication • Functions can invoke effects given different type parameters • Simplifying the effect system, especially, with row polymorphism • Support for abstract effects !31
  • 50. Benefits of duplication • Functions can invoke effects given different type parameters • Simplifying the effect system, especially, with row polymorphism • Support for abstract effects !32
  • 51. Benefit 1 Functions can invoke effects given different type parameters !33 let f () =
 if #choose(true, false)
 then #choose(1, 2) 
 else #choose(10, 20)
  • 52. Benefit 1 Functions can invoke effects given different type parameters !33 let f () =
 if #choose(true, false)
 then #choose(1, 2) 
 else #choose(10, 20) bool choose
  • 53. Benefit 1 Functions can invoke effects given different type parameters !33 let f () =
 if #choose(true, false)
 then #choose(1, 2) 
 else #choose(10, 20) bool choose Int chooseint choose
  • 54. Benefit 1 Functions can invoke effects given different type parameters !33 let f () =
 if #choose(true, false)
 then #choose(1, 2) 
 else #choose(10, 20) bool choose Int chooseint choose f : unit !〈bool choose, int choose〉int
  • 55. Handling duplicated effects Effects are handled from the leftmost among ones having the same name !34 let f
 (g : unit !〈int choose, bool choose〉unit) =
 handle g () with
 return x ! 0
 int choose (x,y) ! 1
  • 56. Handling duplicated effects Effects are handled from the leftmost among ones having the same name !35 let f
 (g : unit !〈int choose, bool choose〉unit) =
 handle g () with
 return x ! 0
 bool choose (x,y) ! 1
  • 57. Conclusion • Algebraic effects & handlers are a means 
 to give user-defined effects • Effect systems structure and analyze 
 effectful behavior of programs • Row-based systems are expressive and amenable !36
  • 58. Call for collaboration Research interests • New effect systems to capture and structure effectful behavior • Efficient implementation of effect handlers • Practical applications of effects 
 (and continuations) !37