[racket] sort in typed racket

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Mon Feb 21 15:37:40 EST 2011

I tried the following:

    (sort  '("hello" "world") string<?)


I received the following error message:

: Type Checker: Cannot apply expression of type (All (a b)
(case-lambda ((Listof a) (a a -> Boolean) [#:cache-keys? Boolean] ->
(Listof a)) ((Listof a) (b b -> Boolean) [#:cache-keys? Boolean] #:key
(a -> b) -> (Listof a)))), since it is not a function type in: (sort
(quote ("hello" "world")) string<?)

I think I see that the typing system doesn't know how to instantiate
b, given that I'm not using the #:key option, so it can't completely
type this expression.  Still, this is a bit weird and unexpected.

I've been able to work around this by explicitly instantiating b with
a dummy value:

    (define string-sort (inst sort String String))

after which I can use string-sort without problems.



I tried a related sort with less success:

    (sort '(hello world) #:key symbol->string string<?)

with a different kind of error that I haven't been able to resolve:

: Type Checker: Inference for polymorphic keyword functions not
supported in: (sort (quote (hello world)) #:key symbol->string
string<?)




Is there something else I'm missing here?


Posted on the users mailing list.