Programs in context
Dominic Orchard,
Cambridge Programming Research Group, University of Cambridge
Monday 12th November 2012
Programs in context Monday 12 th November 2012 Dominic Orchard, - - PowerPoint PPT Presentation
Programs in context Monday 12 th November 2012 Dominic Orchard, Cambridge Programming Research Group, University of Cambridge The Four Rs of effective PLs Riting Reading Running Reasoning (Orchard D, The Four Rs of programming
Dominic Orchard,
Cambridge Programming Research Group, University of Cambridge
Monday 12th November 2012
(Orchard D, The Four Rs of programming language design, Addendum to ONWARD '11 Proceedings)
Universe 2006, Claude Heath
Pure Visitor Partial Programming idioms Language designs Compiler implementations
Universe 2006, Claude Heath
Pure Visitor Partial Programming idioms Language designs Compiler implementations Contextual
52.205337,0.121817 52.205340,0.121837 52.205349,0.121901
λx. ... λx. ... λx. ... λx. ...
for i = 0 to n for j = 0 to m B[i][j] = f(A, i, j)
a a a a a a a a a b b b b b b b b b
f(A, i, j) = (A(i-1,j) + A(i+1,j) + A(i,j-1) + A(i, j+1) + A(i, j)) / 5
local operation, at some context global traversal
f global traversal f local operation
for i = 0 to n for j = 0 to m B[i][j] = 0 for x = 1 to (n-1) for y = 1 to (m-1) B[x][y] = f(A, x, y)
{n,m,f,A,B,i} {n,m,f,A,B,i,j} {n,m,f,A,B,i,j} {n,m,f,A,B,x} {n,m,f,A,B,x,y} {n,m,f,A,B,x,y}
i = <0, ..., n, 1, ..., n-1> j = <0, ..., m, 1, ..., m-1> for i = 0 to n for j = 0 to m B[i][j] = 0 for i = 1 to (n-1) for j = 1 to (m-1) B[i][j] = f(A, i, j)
x + 1 : ?
y : Int ⊢ (fn x . x + y) : Int " Int
x + 1 :
x : Int ⊢ Int
encodes context
(Uustalu, Vene - 2008)
∅?{gps} ⊢ access gps : Coord ∅?{} ⊢ (fn x . access gps + x) : Int " Coord
{gps}
(Petricek, Orchard, Mycroft - 2012)
latent coeffect
encodes context that satisfies R
(Petricek, Orchard, Mycroft - 2012)
coeffects types
“what” “how”
!1 ? c1 ⊢ e1 : t1 !2 ? c2 ⊢ e2 : t2 #(!1, !2) ? c1⊛c2 ⊢ E(e1,e2) : T(t1,t2)
premise conclusion
syntax tree
! ? F ⊢ 3 : Int
dead context
! ? T ⊢ x : t
live context
!?{r} ⊢ access r : t ! ? f1 ⊢ e : t1 " t2
f2
! ? f1 ⊢ send device e : ()
(device has f2 resources)
send client (fn name . insert (access db) “location” name (access gps))
resources
resources
liveness
{r,u}
F
r = x ⨅ y
⨅ = ⋃
{s}
(possibility 1)
y
r = x ⨅ y
⨅ = ⋃
{r}
(possibility 2)
y
r = x ⨅ y
⨅ = ⋃
{}
(possibility 3) and so on...
y
r = x ⨅ y
! ? f1 ⊢ e : t1 " t2
f2
! ? f1 ⊢ send device e : ()
(device has f2 resources)
⨅ = ⋃
y
r = x ⨅ y
liveness ⨅ = ⋀
T y
y
r = x ⨅ y
liveness ⨅ = ⋀
T
(possibility 1) etc.
!, x : t1 ? x ⨅ y ⊢ e : t2 ! ⊢ (fn x . e) : t1 " t2 ? x
y
For a coeffect algebra (C,⊔,⊕,⊓,e)
⊢ e1(e2) : t ! ? x ⊔ (y ⊕ z) ! ? x ⊢ e1 : s " t !? y ⊢ e2 : s
z
! ? x ⊢ e1 : t1 ! ? y ⊢ e2 : t2 ! ? x ⊔ y ⊢ (e1, e2) : (t1, t2) x : t1 ∈ ! ! ? e ⊢ x : t1
(Orchard, Mycroft - 2010)
? traverse interior
exterior provides boundary values
A : Float ? {(0,0),(-1,0),(1,0),(0,1),(0,-1)} ⊢ (A[0][0] + A[-1][0] +
A[1][0] + A[0][1] + A[0][-1])/5.0 : Float
f(A, i, j) = (A(i-1,j) + A(i+1,j) + A(i,j-1) + A(i, j+1) + A(i, j)) / 5
local operation, at some context
! ⊢ e : t
!; !’ ? r ⊢ e : t
exterior size data access
stencil A . (A[0][0] + A[-1][0] +
A[1][0] + A[0][1] + A[0][-1]) /5.0
stencil | _ t _ |
| l @c r | | _ b _ | . (t + l + c + r + b)/5.0
May appear in your work
Ypnos)
“Thanks”
More details in: “Coeffects: The Essence of Context-Dependence”, Petricek, Orchard, Mycroft 2012 “Programming in context” (thesis), Orchard, Coming Soon