aboutsummaryrefslogtreecommitdiff
path: root/examples/functional.halk
blob: d050662ec2aee53d2b423cdb84591c432cc72169 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[the Y combinator, implemented in HALK. Note the
use of '=>' instead of '->', to denote a function
whom's arguments are immutable.]

let.Y => {
   λ.b => {
      (λ.f => { b.λ.x => { (f.f).x } }).
      (λ.f => { b.λ.x => { (f.f).x } });
   }
}

let.Fact => {
   Y.λ.fact => {λ.n => {
      if.(zero?.n), {
         1;
      }, {
         *.n, (fact. -.n, 1);
      }
   }}
}

(define Fact
  (Y (λ (fact) (λ (n) (if (zero? n) 1 (* n (fact (- n 1))))))))