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

Re: [Scheme-reports] WG2 Scheme and Polymporphism



Am 14.10.2011 14:20, schrieb Alaric Snell-Pym:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 10/14/2011 01:07 PM, Denis Washington wrote:
>
>> Hello,
>>
>> Now with the WG1 process nearing its final draft, I thought it might be
>> time to think about what would be great to have in WG2. (I am neither a
>> WG1 or WG2 member, but I care a lot about Scheme.) There seem to be
>> quite a lot of ideas and proposals for this on the WG wiki already [1],
>> but I think that a major thing is missing that I would expect from a
>> modern language in this age: first-class support for polymorphism and
>> generic programming.
>
> That would be nice, yes.
>
>> - Adding generic variant to the set of WG1 procedures where appropiate,
>> and/or redefining existing WG1 procedures to be generic. (For instance,
>> "map" could be redefined to work on arbitrary sequences, with a new
>> "list-map" procedure handling the special case of lists.)
>
> That would finally close the niggling inconsistency of giving list
> procedures nice names than the vector/string/etc equivalents ;-)
>
>> - Adding a way for programmers to define new kinds of polymorphic (sets
>> of) procedures.
>>
>> For the latter, I propose to look into adding something like the
>> "protocols" feature of Clojure [2] into Scheme. In short, this feature
>> allows the definition of a set of procedures that would have to be
>> implemented for a type to "conform to the protocol".
>
> Is that necessary, as opposed to a basic define-generic / define-method
> mechanism? I'd quite like to see generic functions defined orthogonally
> to records-with-inheritance, too, if possible. Although records are the
> only standard way of creating disjoint user types, so there would
> obviously be a tight linkage between the two in practice, I see no
> reason to intertwine their semantics.

Protocols in Clojure are orthogonal to types. There is no inheritance or 
some such, just a flat set of protocols and types that implement them. 
define-generic / define-method is nice, but harder to implement efficiently.

>> This mechanism only supports single type-based dispatch, but in most
>> cases this is all that is needed, and this is very efficient to
>> implement on most platforms (the JVM and CLR have very fast single
>> dispatch, for instance).
>
> Aw, but multiply-dispatched generic functions are awesome!

Nobody forbids implementers to add multiple dispatch, too. I think that 
single dispatch is better as a ubiquitous default system, though, 
because of its performance and ease of implementations in 
object-oriented VMs (JVM, CLR etc.)
>
> ABS
>
> - --
> Alaric Snell-Pym
> http://www.snell-pym.org.uk/alaric/
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.11 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk6YKPAACgkQRgz/WHNxCGqx3wCfetf4jD3Pfx6QUmsmX8b78X+H
> JnMAn0t/0H2pdBAbC50cgzYV797sFV9d
> =tnIA
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> Scheme-reports mailing list
> Scheme-reports@x
> http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports


_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports