Open
Description
Racket version 8.0 [cs]
Why does it work
#lang typed/racket
(define-type Term (Listof (U Symbol Term)))
(: get-tokens (-> Term (Listof Symbol)))
(define (get-tokens term)
(match term
[`() `()]
[`(,(? list? tk) . ,tks) `(,@(get-tokens tk) ,@(get-tokens tks))]
[`(,(? symbol? tk) . ,tks) `(,tk ,@(get-tokens tks))]))
And it doesn't work?
#lang typed/racket
(define-type Term (Listof (U Symbol Term)))
(: get-tokens (-> Term (Listof Symbol)))
(define (get-tokens term)
(match term
[`() `()]
[`(,(? list? tk) ,tks ...) `(,@(get-tokens tk) ,@(get-tokens tks))]
[`(,(? symbol? tk) ,tks ...) `(,tk ,@(get-tokens tks))]))
Error
. Type Checker: type mismatch
expected: Term
given: (Listof Any) in: tks
. Type Checker: type mismatch
expected: Term
given: (U Symbol Term) in: tks
. Type Checker: Summary: 2 errors encountered in:
tks
tks