7

I'm working through Simon Peyton Jones' "The Implementation of Functional Programming Languages" and on page 20 I see:

IF TRUE ((λp.p) 3) ↔ IF TRUE 3         (per β red)   (1)
                   ↔ (λx.IF TRUE 3 x)  (per η red)   (2)
                   ↔ (λx.3)                          (3)

Step 1 to 2 is explained as η-conversion. But from 2 to 3 it says "The final step is the reduction rule for IF." I'm not sure what this reduction rule is.

Kaveh
  • 22,661
  • 4
  • 53
  • 113

1 Answers1

10

The reduction rule you ask for is the usual one for IF statements. It consists of two computation rules and one context rule:

  • $\text{IF TRUE}$ $a$ $b$ $\to$ $a$

  • $\text{IF FALSE}$ $a$ $b$ $\to$ $b$

  • $\dfrac{a\to a'}{\text{IF}~a\ b\ c\to \text{IF}~a'\ b\ c}$

In both the call-by-value (strict) and call-by-need (lazy) settings, both $a$ and $b$ can be arbitrary expressions. They need not be values.

Rules of this kind, that reduce specific functions (here IF), are often called delta rules.

Now, the reason step (2) above is necessary is so that the reduction rules for $\text{IF}$ can apply. $\text{IF}$ requires 3 arguments, but in the original term it has only two, so cannot be reduced. ($\text{IF}$ is being partially applied, just like any function in Haskell. This means that only part of its arguments need to be supplied.) The use of $\eta$-expansion provides the additional argument, without changing the semantics.

Raphael
  • 73,212
  • 30
  • 182
  • 400
Dave Clarke
  • 20,345
  • 4
  • 70
  • 114