[plt-scheme] Typed-Scheme and car

From: David Van Horn (dvanhorn at ccs.neu.edu)
Date: Sun Apr 5 14:44:01 EDT 2009

Paulo J. Matos wrote:
> On Sun, Apr 5, 2009 at 6:30 PM, Paulo J. Matos <pocmatos at gmail.com> wrote:
>> On Sun, Apr 5, 2009 at 6:18 PM, Matthias Felleisen <matthias at ccs.neu.edu> wrote:
>>> Would this
>>>> #lang typed-scheme
>>>> (define x (list (cons 'one 1) (cons 'two 2) (cons 'three 3)))
>>>> (define y ({inst map Symbol (Pair Symbol Integer)} car x))
>>> make you happier? Local inference can't infer at which type map is used
>>> here. That's why you need to declare it.
>> If no inference is possible that's definitely better. Seems I am still
>> learning my way around typed-scheme. :)
> Something else I would say is that it's not really clear why you type
> map with Symbol and (Pair Symbol Integer), since map receives in this
> case a function (Pair Symbol Integer) returning a Symbol and a (Listof
>  (Pair Symbol Integer)) itself returns a (Listof Symbol). So, having
> {inst map Symbol (Pair Symbol Integer)} is quite unclear. I understand
> that we are assigning specific types to the polymorphic types of the
> type definition for map, but the problem is that the user needs to
> know how the type of a specific function is written (order of types
> and polymorphic variables used) and none of this seems written
> anywhere. For example, even if know that map needs to be explicitly
> typed in this case, why {inst map Symbol (Pair Symbol Integer)} and
> not {inst map (Pair Symbol Integer) Symbol} ?

You can read the type of map to see this:

Welcome to DrScheme, version [3m].
Language: Module custom; memory limit: 512 megabytes.
 > map
- : (All (c a b ...) ((a b ... b -> c) (Listof a) (Listof b) ... b -> 
(Listof c)))


Posted on the users mailing list.