Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Fibonacci

examples/fibonacci.sld:

;; The smallest complete program: a typed recursive function and output.
(import
 (snail core base)
 (snail core io))

(define (fibonacci (n I64)) (→ I64)
  (if (< n 2) n (+ (fibonacci (- n 1)) (fibonacci (- n 2)))))

(define (main (out OutputPort)) (→ Unit)
  (display out (fibonacci 30))
  (newline out)
  (unit))

It prints:

832040