SlideShare a Scribd company logo
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

Freer Monads, More Extensible Effects
Freer Monads, More Extensible EffectsFreer Monads, More Extensible Effects
Freer Monads, More Extensible Effects
Hiromi Ishii
 
Introduction to Regular Expressions
Introduction to Regular ExpressionsIntroduction to Regular Expressions
Introduction to Regular Expressions
Matt Casto
 
katagaitai CTF勉強会 #5 Crypto
katagaitai CTF勉強会 #5 Cryptokatagaitai CTF勉強会 #5 Crypto
katagaitai CTF勉強会 #5 Crypto
trmr
 
JavaからScala、そしてClojureへ: 実務で活きる関数型プログラミング
JavaからScala、そしてClojureへ: 実務で活きる関数型プログラミングJavaからScala、そしてClojureへ: 実務で活きる関数型プログラミング
JavaからScala、そしてClojureへ: 実務で活きる関数型プログラミング
Kent Ohashi
 
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
Scott Wlaschin
 
プログラムの処方箋~健康なコードと病んだコード
プログラムの処方箋~健康なコードと病んだコードプログラムの処方箋~健康なコードと病んだコード
プログラムの処方箋~健康なコードと病んだコード
Shigenori Sagawa
 
Format string Attack
Format string AttackFormat string Attack
Format string Attack
icchy
 
オブジェクト指向できていますか?
オブジェクト指向できていますか?オブジェクト指向できていますか?
オブジェクト指向できていますか?Moriharu Ohzu
 
ClojurianからみたElixir
ClojurianからみたElixirClojurianからみたElixir
ClojurianからみたElixir
Kent Ohashi
 
Behatで行う、E2Eテスト入門
Behatで行う、E2Eテスト入門Behatで行う、E2Eテスト入門
Behatで行う、E2Eテスト入門
leverages_event
 
Domain Modeling Made Functional (KanDDDinsky 2019)
Domain Modeling Made Functional (KanDDDinsky 2019)Domain Modeling Made Functional (KanDDDinsky 2019)
Domain Modeling Made Functional (KanDDDinsky 2019)
Scott Wlaschin
 
10. Recursion
10. Recursion10. Recursion
10. Recursion
Intro C# Book
 
Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examples
greatqadirgee4u
 
Scala の関数型プログラミングを支える技術
Scala の関数型プログラミングを支える技術Scala の関数型プログラミングを支える技術
Scala の関数型プログラミングを支える技術
Naoki Aoyama
 
【TECH×GAME COLLEGE#28】形から入ったドメイン駆動設計によるゲーム開発の光と闇
【TECH×GAME COLLEGE#28】形から入ったドメイン駆動設計によるゲーム開発の光と闇【TECH×GAME COLLEGE#28】形から入ったドメイン駆動設計によるゲーム開発の光と闇
【TECH×GAME COLLEGE#28】形から入ったドメイン駆動設計によるゲーム開発の光と闇
techgamecollege
 
PWNの超入門 大和セキュリティ神戸 2018-03-25
PWNの超入門 大和セキュリティ神戸 2018-03-25PWNの超入門 大和セキュリティ神戸 2018-03-25
PWNの超入門 大和セキュリティ神戸 2018-03-25
Isaac Mathis
 
Network lap pgms 7th semester
Network lap pgms 7th semesterNetwork lap pgms 7th semester
Network lap pgms 7th semester
DOSONKA Group
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Mario Fusco
 
本当にわかる Spectre と Meltdown
本当にわかる Spectre と Meltdown本当にわかる Spectre と Meltdown
本当にわかる Spectre と Meltdown
Hirotaka Kawata
 
Introduction to Debuggers
Introduction to DebuggersIntroduction to Debuggers
Introduction to Debuggers
Saumil Shah
 

What's hot (20)

Freer Monads, More Extensible Effects
Freer Monads, More Extensible EffectsFreer Monads, More Extensible Effects
Freer Monads, More Extensible Effects
 
Introduction to Regular Expressions
Introduction to Regular ExpressionsIntroduction to Regular Expressions
Introduction to Regular Expressions
 
katagaitai CTF勉強会 #5 Crypto
katagaitai CTF勉強会 #5 Cryptokatagaitai CTF勉強会 #5 Crypto
katagaitai CTF勉強会 #5 Crypto
 
JavaからScala、そしてClojureへ: 実務で活きる関数型プログラミング
JavaからScala、そしてClojureへ: 実務で活きる関数型プログラミングJavaからScala、そしてClojureへ: 実務で活きる関数型プログラミング
JavaからScala、そしてClojureへ: 実務で活きる関数型プログラミング
 
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
 
プログラムの処方箋~健康なコードと病んだコード
プログラムの処方箋~健康なコードと病んだコードプログラムの処方箋~健康なコードと病んだコード
プログラムの処方箋~健康なコードと病んだコード
 
Format string Attack
Format string AttackFormat string Attack
Format string Attack
 
オブジェクト指向できていますか?
オブジェクト指向できていますか?オブジェクト指向できていますか?
オブジェクト指向できていますか?
 
ClojurianからみたElixir
ClojurianからみたElixirClojurianからみたElixir
ClojurianからみたElixir
 
Behatで行う、E2Eテスト入門
Behatで行う、E2Eテスト入門Behatで行う、E2Eテスト入門
Behatで行う、E2Eテスト入門
 
Domain Modeling Made Functional (KanDDDinsky 2019)
Domain Modeling Made Functional (KanDDDinsky 2019)Domain Modeling Made Functional (KanDDDinsky 2019)
Domain Modeling Made Functional (KanDDDinsky 2019)
 
10. Recursion
10. Recursion10. Recursion
10. Recursion
 
Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examples
 
Scala の関数型プログラミングを支える技術
Scala の関数型プログラミングを支える技術Scala の関数型プログラミングを支える技術
Scala の関数型プログラミングを支える技術
 
【TECH×GAME COLLEGE#28】形から入ったドメイン駆動設計によるゲーム開発の光と闇
【TECH×GAME COLLEGE#28】形から入ったドメイン駆動設計によるゲーム開発の光と闇【TECH×GAME COLLEGE#28】形から入ったドメイン駆動設計によるゲーム開発の光と闇
【TECH×GAME COLLEGE#28】形から入ったドメイン駆動設計によるゲーム開発の光と闇
 
PWNの超入門 大和セキュリティ神戸 2018-03-25
PWNの超入門 大和セキュリティ神戸 2018-03-25PWNの超入門 大和セキュリティ神戸 2018-03-25
PWNの超入門 大和セキュリティ神戸 2018-03-25
 
Network lap pgms 7th semester
Network lap pgms 7th semesterNetwork lap pgms 7th semester
Network lap pgms 7th semester
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
 
本当にわかる Spectre と Meltdown
本当にわかる Spectre と Meltdown本当にわかる Spectre と Meltdown
本当にわかる Spectre と Meltdown
 
Introduction to Debuggers
Introduction to DebuggersIntroduction to Debuggers
Introduction to Debuggers
 

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.pptx
ManojKhadilkar1
 
Declare Your Language: Name Resolution
Declare Your Language: Name ResolutionDeclare Your Language: Name Resolution
Declare Your Language: Name Resolution
Eelco Visser
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2
vikram 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 processing
Sylvain 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).ppt
ssuser26e219
 
Lecture 3 and 4.pptx
Lecture 3 and 4.pptxLecture 3 and 4.pptx
Lecture 3 and 4.pptx
MAHAMASADIK
 
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
Venugopalavarma Raja
 
Python.pptx
Python.pptxPython.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
Venugopalavarma 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 Scala
djspiewak
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
Chukka Nikhil Chakravarthy
 
Python-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptxPython-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptx
ElijahSantos4
 
Python
PythonPython
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.pdf
MILANOP1
 
Tutorial on convolutional neural networks
Tutorial on convolutional neural networksTutorial on convolutional neural networks
Tutorial on convolutional neural networks
Hojin Yang
 
Operators
OperatorsOperators
Operators
loidasacueza
 
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
Patrick Viafore
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)
Scott Wlaschin
 

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
 
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
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)
 

Recently uploaded

Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
Fwdays
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
saastr
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo Gómez Abajo
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
DianaGray10
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
Edge AI and Vision Alliance
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Pitangent Analytics & Technology Solutions Pvt. Ltd
 

Recently uploaded (20)

Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
 

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