Created
April 16, 2017 14:25
-
-
Save LeifAndersen/4d6f3d843f50878d9f296edd69b36a7b to your computer and use it in GitHub Desktop.
Heavy Contracts
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 scratch | |
| (module u racket | |
| (define (fact t-fact x acc lookup mk) | |
| (if (= x 0) | |
| (lookup acc) | |
| (t-fact fact (- x 1) (mk (* (lookup acc) x)) lookup mk))) | |
| (provide fact)) | |
| (module t typed/racket | |
| (define-type (f T) | |
| (-> (-> f Number T (-> T Number) (-> Number T) Number) | |
| Number | |
| T | |
| (-> T Number) | |
| (-> Number T) | |
| Number)) | |
| (: fact f) | |
| (define (fact u-fact x acc lookup mk) | |
| (if (= x 0) | |
| (lookup acc) | |
| (u-fact fact (- x 1) (mk (* (lookup acc) x)) lookup mk))) | |
| (provide fact)) | |
| (struct acc (num)) | |
| (require (rename-in 'u [fact u-fact]) | |
| (rename-in 't [fact t-fact])) | |
| (require feature-profile) | |
| (feature-profile | |
| (u-fact t-fact 5000 (acc 1) acc-num acc)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment