typed-racket/typed-racket-test/succeed/dviu-infer-fact.rkt
Daniel Feltey 2e0cc095c7 Initial support for typed units in typed racket.
Most unit forms are supported, including most of the "infer" forms that
infer imports/exports/linkages from the current context.

Notably, none of the structural linking forms for units are supported, and
`define-unit-binding` is also currently unsupported.
2015-09-10 16:32:11 -05:00

21 lines
443 B
Racket

#lang typed/racket
(define-signature fact^ ([fact : (-> Natural Natural)]))
(define-unit fact@
(import (prefix i: fact^))
(export fact^)
(: fact (-> Natural Natural))
(define (fact n)
(if (= 0 n)
1
(* n (i:fact (sub1 n))))))
;; without link this should fail
;; see the corresponding test for failure:
;; dviu-infer-fact-no-link.rkt in the fail directory
(define-values/invoke-unit/infer (link fact@))
(fact 5)