On Mon, May 31, 2021 at 6:17 AM Marc Nieper-Wißkirchen <
[email protected]> wrote:

> Am Mo., 31. Mai 2021 um 17:53 Uhr schrieb Shiro Kawai <
> [email protected]>:
>
>>
>> That said, explicit conversion was the first one I thought of.  But
>> strict type separation doesn't seem to play well without static
>> parameterized types.
>>
>
> In which sense? Scheme *has* strict type separation (mostly) but a dynamic
> typing system.
>

My concern stems from the fact that enforcing affine types (an object can
be used at most once) dynamically isn't trivial with existing runtime type
identification.  It seems to me that some kind of reference tracking is
necessary.  With appropriate static typing, the compiler can deduce whether
the passed object satisfies the condition or not, and statically dispatch
the code where unnecessary copying is avoided.


> The type distinction doesn't have to be on the level of type predicates.
> Think of pairs here. Some pairs (namely those coming from literals) are
> immutable. Scheme is mostly transparent to this distinction unless you try
> to use set-car! on an immutable type (and given an implementation that
> actually signals an error in this case).
>
[,,,]

> I don't think so. See my pair example from above. Only when actually
> modification happens but a copy to a mutable version of the type was
> forgotten, an assertion violation would be raised.
>

Mutability alone isn't enough to avoid unnecessary copying.  You write an
intermediate library function that wants to take advantage of linear
updating.  You, as a library writer, don't know whether input is immutable
or not, so you're forced to copy the argument.
Yet there'd be cases that the caller knows he's passing a mutable object
that won't ever be reused.

But as your follow-up message says, "passing functional objects to linear
updating version is an error" has enough leeway to implement implicit
conversion if the implementation desires,  so I'm happy with that.

Do you think 'ensure-mutable' interface (only copy when input is immutable)
is desirable to write portable code that can avoid unnecessary copying?

Reply via email to