1 Overview
2 PCF
2.1 Language
2.2 Model
PCF
v
-->v
δ
typeof
typable?
3 CPCF
3.1 Language
3.2 Model
CPCF-source
CPCF
cv
-->cv
typeof/ contract
typable/ contract?
4 SPCF
4.1 Language
4.2 Model
SPCF
sv
-->sv
δ^
typeof/ symbolic
typable/ symbolic?
5 SCPCF
5.1 Language
5.2 Model
SCPCF
typeof/ contract/ symbolic
typable/ contract/ symbolic?
5.3.1.9

PCF with Contracts and Symbolic Values

David Van Horn <dvanhorn@ccs.neu.edu>

https://github.com/dvanhorn/pcf/

    1 Overview

    2 PCF

      2.1 Language

      2.2 Model

    3 CPCF

      3.1 Language

      3.2 Model

    4 SPCF

      4.1 Language

      4.2 Model

    5 SCPCF

      5.1 Language

      5.2 Model

1 Overview

This package contains a collection of modules for exploring and experimenting with (variations on) a core typed functional language based on Plotkin’s PCF.

2 PCF

2.1 Language

 #lang pcf

PCF is a core typed call-by-value functional programming language.

  PCF = M ...
     
  M = X
  | V
  | (M M ...)
  | (μ (X : T) M)
  | (if0 M M M)
  | (err T string)
     
  V = natural
  | O
  | (λ ([X : T] ...) M)
     
  O = add1
  | sub1
  | *
  | +
  | quotient
  | pos?
     
  T = nat
  | (T ... -> T)

Figure 1: PCF Syntax

> 5

5

> (λ ([x : nat]) x)

'(λ ((x : nat)) x)

> ((λ ([x : nat]) x) 5)

5

> (if0 1 2 3)

3

> (if0 0 (add1 2) 8)

3

> (add1 add1)

eval:7:0: type-error: ill-typed expression

  in: (add1 add1)

> (quotient 5 0)

'(err nat "Divide by zero")

As required by Mass law:
> ((μ (fact : (nat -> nat))
      (λ ([n : nat])
        (if0 n
             1
             (* n (fact (sub1 n))))))
   5)

120

2.2 Model

 (require pcf/redex)

language

PCF

image

Figure 2: The PCF language

value

v : reduction-relation?

image

Figure 3: Reduction relation v

value

-->v : reduction-relation?

Contextual closure of v over evaluation contexts.

judgment-form

δ

image

image

Figure 4: Primitive application δ

judgment form

typeof

image

Figure 5: Typing judgment typeof

procedure

(typable? m)  boolean?

  m : (redex-match PCF M)
Is m a well-typed PCF term?

3 CPCF

3.1 Language

 #lang cpcf

  M = ....
  | (C  M)
     
  C = M
  | (C ... -> C)

Figure 6: CPCF Syntax, extending PCF

> ((λ ([x : nat]) x)  3)

'(blame eval:2:0)

> ((λ ([x : nat]) x)  0)

0

> (((λ ([x : nat]) x) -> (λ ([x : nat]) x))
   
   (λ ([x : nat]) x))

'(λ ((x : nat))

   ((λ ((x : nat)) x) ⚖ ((λ ((x : nat)) x) ((λ ((x : nat)) x) ⚖ x))))

> ((((λ ([x : nat]) x) -> (λ ([x : nat]) x))
    
    (λ ([x : nat]) x))
   0)

0

> ((((λ ([x : nat]) x) -> (λ ([x : nat]) 1))
    
    (λ ([x : nat]) x))
   0)

'(blame eval:6:0)

> ((((λ ([x : nat]) 1) -> (λ ([x : nat]) x))
    
    (λ ([x : nat]) x))
   0)

'((λ ((x : nat)) x) ⚖ ((λ ((x : nat)) x) (blame eval:7:0)))

3.2 Model

 (require cpcf/redex)

language

CPCF-source

language

CPCF

image

image

Figure 7: The CPCF-source and CPCF languages

image

Figure 8: Reduction relation cv

value

-->cv : reduction-relation?

Contextual closure of cv over evaluation contexts.

judgment form

typeof/contract

image

image

Figure 9: Typing judgment typeof/contract

procedure

(typable/contract? m)  boolean?

  m : (redex-match CPCF M)
Is m a well-typed PCF term?

4 SPCF

4.1 Language

 #lang spcf

  V = ....
  | ( T)

Figure 10: SPCF Syntax, extending PCF

> (if0 ( nat) 1 2)

1

2

> (add1 (if0 ( nat) 1 2))

2

3

> (add1 (if0 ( nat) 1 ( nat)))

'(• nat)

2

> ((λ ([x : nat]) 1) 2)

1

> ((λ ([f : (nat -> nat)])
     (f (f 5)))
   (λ ([n : nat])
     (quotient 625 n)))

5

> (( ((nat -> nat) -> nat))
   (λ ([n : nat])
     (quotient 625 n)))

'(err nat "Divide by zero")

'(• nat)

> ((λ ([f : (nat -> nat)])
     (f (f 5)))
   ( (nat -> nat)))

'(• nat)

5

4.2 Model

 (require spcf/redex)

language

SPCF

image

Figure 11: The SPCF language

image

Figure 12: Reduction relation sv

image

Figure 13: Havoc

value

-->sv : reduction-relation?

Contextual closure of sv over evaluation contexts.

judgment-form

δ^

image

Figure 14: Abstract primitive application δ^

judgment form

typeof/symbolic

image

Figure 15: Typing judgment typeof/symbolic

procedure

(typable/symbolic? m)  boolean?

  m : (redex-match SPCF M)
Is m a well-typed SPCF term?

5 SCPCF

 #lang scpcf

5.1 Language

  V = ....
  | ( T C ...)

Figure 16: SCPCF Syntax, extending CPCF

> (add1 ( nat pos?))

'(• nat)

> (( ((nat -> nat) -> nat))
   (λ ([n : nat])
     (quotient 625 n)))

'(err nat "Divide by zero")

'(• nat)

> (( ((nat -> nat) -> nat))
   ((pos? -> (λ ([x : nat]) 0))
    
    (λ ([n : nat])
      (quotient 625 n))))

'((λ ((x : nat)) 0) ⚖ ((λ ((n : nat)) (quotient 625 n)) (blame eval:4:0)))

'(• nat (λ ((x : nat)) 0))

'(• nat)

5.2 Model

 (require scpcf/redex)

language

SCPCF

image

Figure 17: The SCPCF language

Contextual closure of scv over evaluation contexts.

judgment form

typeof/contract/symbolic

image

Figure 18: Typing judgment typeof/contract/symbolic

procedure

(typable/contract/symbolic? m)  boolean?

  m : (redex-match SCPCF M)
Is m a well-typed SCPCF term?