[racket] Typed Racket - Parameterized Structures Part Duex
Thanks for the previous TR assist.
I tried manually annotating stuff inside the 'get' procedure below but
can't seem to get it to type check.
Thanks again in advance.
(struct: (T) Try ())
(struct: (T) Failure Try ([exception : exn]))
(struct: (T) Success Try ([result : T]))
(: failed (All (T) (Try T) -> Boolean))
(define (failed try)
(Failure? try))
(: succeded (All (T) (Try T) -> Boolean))
(define (succeded try)
(Success? try))
(: get (All (T) (Try T) -> T))
(define (get try)
(cond
((Failure? try) (raise (Failure-exception try)))
((Success? try) (Success-result try))
(else (error "Can I not be 'sealed'"))))
(: tmap (All (T U) (Try T) (T -> U) -> (Try U)))
(define (tmap try fn)
(cond
((Success? try)
(Try (fn (Success-result try))))
((Failure? try) try)
(else (error "hmmmm"))))
(: attempt (Try String))
(define attempt (Success "Good to go"))
(: test (-> String))
(define (test)
(if (succeded attempt)
(get attempt)
"aborted"))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120316/96de2734/attachment-0001.html>