Created
December 8, 2016 01:36
-
-
Save winny-/5988f5fbc894212b0e824477422eccb4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang typed/racket | |
(: fib (Exact-Nonnegative-Integer . -> . Exact-Nonnegative-Integer)) | |
(define (fib n) | |
(cond | |
[(< n 2) 1] | |
[else (+ (fib (sub1 n)) | |
(fib (- n 2)))])) | |
zenspider
commented
Dec 8, 2016
That's wonderful, thanks!
(: fib (Integer . -> . Exact-Nonnegative-Integer))
(define (fib n)
(: -- (-> Integer Exact-Nonnegative-Integer Exact-Nonnegative-Integer))
(define (-- a b) (cast (- a b) Exact-Nonnegative-Integer))
(cond
[(< n 2) 1]
[else (+ (fib (-- n 1))
(fib (-- n 2)))]))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment