[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-hackers] [PATCH][5] Change procedure argument type relation

From: megane
Subject: Re: [Chicken-hackers] [PATCH][5] Change procedure argument type relation to contravariant
Date: Mon, 28 May 2018 18:11:31 +0300
User-agent: mu4e 0.9.18; emacs 25.1.1


Here's a new version of the patch. This tries to handle #!optional and
#!rest in procedure types correctly, in addition to the parameter
contravariance stuff. The implementation should be cleaner now.

This is still not ready to be merged to the master. At least the
signatures in types.db should be fixed first.

This doesn't try to address any of the issues I raised in the parent
post. Instead, it adds at least one new one:

This is the type for 'map' from the types.db:
(scheme#map (forall (a b)
  (#(procedure #:enforce) scheme#map
     (procedure (a #!rest) b)
     (list-of a)
     #!rest list
    (list-of b))))

(Note that the first parameter to map is declared as (a #!rest -> b).)

The scrutinizer checks that the function you pass to map is a subtype
(or of equal type) to the declared parameter type. That is, the function
has to handle all parameters of the declared type (a and #!rest), but
can be more permissive. (Also the result type has to be b or it's

But for example (a -> b) is not a subtype of (a #!rest -> b), it only
allows for one parameter of type a. (Maybe passing more parameters could
cause runtime error or worse.). This means that (map add1 '(1)) fails to
type check.

Fortunately this is easy to fix by removing the #!rest from the type
signature. This shouldn't make the type any less safe than it already is
(unless there's some special case(s) in the scrutinizer I'm unaware of).
The number of arguments wasn't checked to match to the argument count to
map anyway.

Ideally you'd have some way to unify the #!rest in the map's first
argument and the #!rest for map. Maybe some other time.

Attachment: procedure-argument-contravariance-v2.patch
Description: Text Data

reply via email to

[Prev in Thread] Current Thread [Next in Thread]