2 minute read

Here we will talk about computational interpretations by the example of lax logic. Hope from the example we can have sense of how logic and PL are connected.

Lax and MonandPermalink

Some notations:

ΓE:A lax means E as a computational evidence might not terminate. It might not give me A at the end. Think of it like a “possibility” that E will give me A.

{E} a suspended computation of E.

<E/x>F is a kind of substitution of E for x in F. It is an operration on proof/computation. Will talk about it later.

So we have the following structural rules or judgemental rules about lax:

1.

ΓM:A trueΓM:A lax

2.

ΓE:A lax,Γx:A trueF:C laxΓ⊢<E/x>F:C lax

We now introduce a new proposition A Monad:

Introduction rule (I):

ΓE:A laxΓ{E}:A true

Elimination rules (E):

ΓM:A true,Γx:A trueF:C laxΓlet_{x}=Min_F:C lax

Summarize local reduction and local expansion:

let_{x}={E}in_FR<E/x>F M:AE{let_{x}=Min_x}

So because E is type of A lax, according to the second structural rules about lax: ΓE:A lax,Γx:A trueF:C laxΓ⊢<E/x>F:C lax, it could be comming from two places:

  1. The first structural rules about lax: ΓM:A trueΓM:A lax. So E is M.

  2. The elimination rules of A: ΓM:A true,Γx:A trueF:C laxΓlet_{x}=Min_F:C lax. (Note: Here F and C could be anything). So E is let_{x}=Min_F

So we write: E=M|let_{x}=Min_F

For the elimination rule case, we can see ΓM:A true. For something have type A, according to the Introduction rule of A, it could be that M=E

Therefore, M is everything as before plus one possibility:

We write: M={E}

Then we can define <E/x>F:

<E/x>F=<M/x>F=[M/x]For<let_{y}=Min_E/x>F=let_{y}=Min_<E/x>F

Let’s Write Some Proofs/ProgramsPermalink

For (A(BC))((AB)C) which is uncurrying, we have the proof: λf.λp.f(first p)(second p)

For ((AB)C)(A(BC)) which is currying, we have the proof: λg.λx.λy.g<x,y>

For monad in functional programming we have two requirements to satisfy:

return:AAbind:A(AB)B

such that

bind(return z)f=fz

To proof return:

AA

we have:

λx.{x}

To proof bind:

A(AB)B

we have:

λx.λf.{let_{x}=xin_ let_{y}=fxin_ y}

To proof

bind(return x)f=fx

we have:

(λx.λf.{let_{x}=x in_ let_{y}=fx in_ y})((λx.{x})z)f={let_{x}=(λx.{x})z in_ let_{y}=fx in_ y}={let_{x}={z} in_ let_{y}=fx in_ y}={let_{y}=fz in_ y}=fz

Comments