PasteRack.org
Paste # 41494
2015-05-19 04:59:35

Fork as a new paste.

Paste viewed 483 times.


Embed:

Y combinator in typed/racket without using (define …)

  1. #lang typed/racket
  2.  
  3. ((;; Y combinator
  4.   (;(ann ;; Not needed
  5.     (λ (f)
  6.       (f f))
  7.    ;(All (A) (→ (Rec r (→ r A)) A))) ;; Not needed
  8.    (ann
  9.     (λ (z)
  10.       (λ (f)
  11.         (f (λ (x) (((z z) f) x)))))
  12.     (Rec r ( r (All (T R) ( ( ( T R) ( T R)) ( T R)))))))
  13.   ;; Recursive function
  14.   (λ ([recursive-factorial : ( Real Real)])
  15.     (λ ([x : Real])
  16.       (if (<= x 0)
  17.           1
  18.           (* x (recursive-factorial (- x 1)))))))
  19.  5)

=>

- : Real

120