Hi, in non-typed racket, I can define a generalized Fibonacci sequence 

X[n+k] = f(X[n], X[n+1], ...., X[n+k-1])

using the following code 

#lang racket

(require  racket/stream)

(define (gfib f xs)
  (define (gfib_t xs)
    (stream-cons (last xs) (gfib_t (append (cdr xs) (list (f xs)))))) 
  (stream-append (drop-right xs 1) (gfib_t xs)))

(define (sum xs) (apply + xs))
;; Example of a (0, 1) initialized Fibonacci sequence 
(define gfib20 (gfib sum '(0 1 )))

But using typed racket,  the following code 

#lang typed/racket

(require pfds/stream)

(define (sum [xs : (Listof Number)] ) (apply + xs))

(define (gfib [f : (-> (Listof Number) Number)]  [xs : (Listof Number)] )
  (define (gfib_t [ys : (Listof Number)] )  
    (stream-cons (last ys) (gfib_t (append (cdr ys) (list (f ys))))))
  (stream-append (stream (drop-right xs 1)) (gfib_t xs)))

leads to error message 

; /home/kiong-ge/Programming/Racket/typed_racket_test.rkt:8:11: Type 
Checker: insufficient type information to typecheck. please add more type 
annotations
;   in: gfib_t

How should I set the type signature in the typed racket in order to get the 
same result generated non-typed racket code ?

Thanks, 
Kiong-Ge. 



-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/baa0af81-f7fb-46bf-b508-d35727cbaef2n%40googlegroups.com.

Reply via email to