On 7/13/21, Kiong-Gē Liāu <[email protected]> wrote:
> Ben,
>
> Thanks, changing "stream" to "stream apply" does solve the issue.
>
> I tried to push it further little bit with the following code to see if
> typed racket can support generic like Haskell or Scala:
>
> #lang typed/racket
>
> (require pfds/stream)
>
>
> (define-type (OverFoldable A) (-> (Listof A) A))
>
> (define-type (FibStreamCons A) (-> (Listof A) (Stream A)))
>
> (define-type (FibStream A) (-> (OverFoldable A) (Listof A) (Stream A)))
>
> (: sum (OverFoldable Number))
> (define (sum xs) (apply + xs))
>
> (: gfib_2 (All (A) (FibStream A)))
> (define (gfib_2 f xs)
>   (: gfib_t (All (A) (FibStreamCons A)))
>   (define (gfib_t ys)
>     (stream-cons (last ys) (gfib_t (append (cdr ys) (list (f ys))))))
>   (stream-append (apply stream (drop-right xs 1)) (gfib_t xs)))
>
> However, I got the following error message:
>
> ; /home/kiong-ge/Programming/Racket/typed_racket_test.rkt:28:61: Type
> Checker: type mismatch
> ;   expected: (Listof A)
> ;   given: (Listof A)
> ;   in: ys
>
> But, according to this error message, expected and given types are exactly
> the same, not sure how to deal with this issue.

I think the problem is 2 different type variables that both print as
the letter A.

When I remove the "All" from the type for gfib_t (FibStreamCons A), it
typechecks.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAFUu9R5nuj-peuqFRVFRR6fKY4waAwaXNdTbmJzNfVTBBx9GbQ%40mail.gmail.com.

Reply via email to