[plt-scheme] Typed-Scheme and car

From: Paulo J. Matos (pocmatos at gmail.com)
Date: Sun Apr 5 14:51:05 EDT 2009

On Sun, Apr 5, 2009 at 6:44 PM, David Van Horn <dvanhorn at ccs.neu.edu> wrote:
> 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 4.1.5.3-svn2apr2009 [3m].
> Language: Module custom; memory limit: 512 megabytes.
>> map
> - : (All (c a b ...) ((a b ... b -> c) (Listof a) (Listof b) ... b ->
> (Listof c)))
> #<procedure:map>
>

You are right, thanks for reminding me of that...
Anyway, in the future will the documentation contain the types for
each function ?
For example, current doc:
(map proc lst ...+) → list?
  proc : procedure?
  lst : list?

Future doc:
(map proc lst ...+) → list?
  proc : procedure?
  lst : list?
typed-scheme: (All (c a b ...) ((a b ... b -> c) (Listof a) (Listof b)
... b ->  (Listof c)))

On other issue... how does this happen in Haskell, doesn't haskell
figure the types out for map?
What's the major difference between haskell and typed-scheme in this case?

Cheers,

Paulo Matos

> David
>



-- 
Paulo Jorge Matos - pocmatos at gmail.com
Webpage: http://www.personal.soton.ac.uk/pocm


Posted on the users mailing list.