[Haskell-cafe] Strict type system allows for a maximum number of programming errors to be caught at compile time.

Luke Palmer lrpalmer at gmail.com
Tue May 4 01:02:36 EDT 2010


On Mon, May 3, 2010 at 10:13 PM, Ivan Miljenovic
<ivan.miljenovic at gmail.com> wrote:
> On 4 May 2010 13:30, Luke Palmer <lrpalmer at gmail.com> wrote:
>> Here is a contrived example of what I am referring to:
>>
>> prefac f 0 = 1
>> prefac f n = n * f (n-1)
>>
>> fac = (\x -> x x) (\x -> prefac (x x))
>
> I can't work out how this works (or should work rather); is it meant
> to be using church numerals or something (assuming that they have been
> made an instance of Num so that - and * work)?

No they're just integers.  fac is a beta expansion of fix prefac.
Obseve the magic:

   (\x -> x x) (\x -> prefac (x x)) 2
   (\x -> prefac (x x)) (\x -> prefac (x x)) 2
   prefac ((\x -> prefac (x x)) (\x -> prefac (x x))) 2
   2 * ((\x -> prefac (x x)) (\x -> prefac (x x)) (2-1)
   2 * prefac ((\x -> prefac (x x)) (\x -> prefac (x x))) (2-1)
      2 * prefac ((\x -> prefac (x x)) (\x -> prefac (x x))) 1
   2 * (1 * ((\x -> prefac (x x)) (\x -> prefac (x x))) (1-1))
   2 * (1 * prefac ((\x -> prefac (x x)) (\x -> prefac (x x))) (1-1))
   2 * (1 * prefac ((\x -> prefac (x x)) (\x -> prefac (x x))) 0)
   2 * (1 * 1)
   2

Luke


More information about the Haskell-Cafe mailing list