I'm struggling with the syntax for a function that zips together any number of lists. I currently have:
(define (zip . [lsts : (Listof Any) *])
(apply map (inst list Any) lsts))
Which causes the following error when evaluated:
Error: struct:exn:fail:syntax /Applications/Racket v6.6/collects/racket/private/kw.rkt:929:25: Type Checker: Bad arguments to function in `apply':
Domains: (-> a b ... b c) (Listof a) (Listof b) ... b
(-> a c) (Pairof a (Listof a))
Arguments: (-> Any * (Listof Any)) (Listof (Listof Any)) *
in: (#%app apply map (#%expression list) lsts)
Since these evaluate okay:
(apply map (inst list Any) '(("asd" 1 2) ("cat" 3 4)))
;;(("asd" "cat") (1 3) (2 4))
(define (test . [lsts : (Listof Any) *])
lsts)
(test '(1 2 3) '(2 3 "dogs"))
;;((1 2 3) (2 3 "dogs"))
I think the type checker's complaining about apply
failing whenever no arguments are passed in, since I get a similar error trying to evaluate the following:
(apply map (inst list Any) '())
Error: struct:exn:fail:syntax /Applications/Racket v6.6/collects/racket/private/kw.rkt:929:25: Type Checker: Bad arguments to function in `apply':
Domains: (-> a b ... b c) (Listof a) (Listof b) ... b
(-> a c) (Pairof a (Listof a))
Arguments: (-> Any * (Listof Any)) Null *
in: (#%app apply map (#%expression list) (quote ()))
But I'm not sure how to specify to the function that it'll take at least one argument (list).