--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I don't need full power of generics wild application rules. I just need a comfortable way to paste some field and method definitions into my type.
When people says "we want generics" they really says "we want code generation".
24.05.2014 16:06 пользователь "chris dollin" <ehog....@googlemail.com> написал:
There is only three ways to implement polymorphic functions: code generation, dinamyc dispatch, and interpretation. Both dispatch and interpretation still assumes, that there is more code produced/evaluated then one had wrote.
I think, SML generates code for each parameter combination of polymorphic function, and may be uses interpretation for repl.
24.05.2014 16:06 пользователь "chris dollin" <ehog....@googlemail.com> написал:
> Ummm ... no.
>
> What they want may be /implemented/ using code generation. It isn't
> the code generation that's the requirement.
>
> (Consider SML, which has polymorphic functions not implemented
> with "code generation".)
There is only three ways to implement polymorphic functions: code generation, dinamyc dispatch, and interpretation.
I think, SML generates code for each parameter combination of polymorphic function,
and may be uses interpretation for repl.
24.05.2014 20:33 пользователь "chris dollin" <ehog....@googlemail.com> написал:
>
> On 24 May 2014 16:47, Юрий Соколов <funny....@gmail.com> wrote:
>>
>>
>> 24.05.2014 16:06 пользователь "chris dollin" <ehog....@googlemail.com> написал:
>>
>> > Ummm ... no.
>>
>> >
>> > What they want may be /implemented/ using code generation. It isn't
>> > the code generation that's the requirement.
>> >
>> > (Consider SML, which has polymorphic functions not implemented
>> > with "code generation".)
>>
>> There is only three ways to implement polymorphic functions: code generation, dinamyc dispatch, and interpretation.
>
> I don't think a typical SML implementation does any of those
> things for polymorphic functions. It just has a uniform size for
> data values (and an appropriate type system) -- hence large
> structures (for a small value of "large") are boxed.
So that, it ought to use dispatch.
>
> Note that SML's polymorphism is /parametric/ polymorphism,
> not OO-style polymorphism.
Dispatch could like OO-style polimorphism, and could like not. It is still dispatch.
>>
>> I think, SML generates code for each parameter combination of polymorphic function,
>
> I don't think so. It doesn't need to.
If it is true, then it ought to use dispatch, as i said.
Consider: C# specialize templates only for value types, and all reference types uses same generated code with reliance on dispatch+jit. And Java have one code for all template instantiations, relying on dispatch+jit even more.
>
> (An /optimising/ compiler is of course free to make extra code
> specialised as appropriate to the program at hand, but that's
> a different game of dominoes.)
>
Making extra code is a single way to avoid dispatch.
>>
>> and may be uses interpretation for repl.
>
> I'd expect incremental compilation rather than interpretation.
> Certainly the Poplog implementation of SML does that.
I was not sure and said "may be".
Go has a dispatch with interfaces, and it is really good for "bussiness code". But when performance is needed, then code generation is only way.
And, of cause type safety suffers a bit with interfaces - second need for generics/code generation(/may be polimorhics).
I don't think a typical SML implementation does any of those
things for polymorphic functions. It just has a uniform size for
data values (and an appropriate type system) -- hence largestructures (for a small value of "large") are boxed.
So that, it ought to use dispatch.
And still, it is just implementation details. Semantically, polimorphics are still code generation: instead of writting function instance for each argument combination, you wrote rule to evaluator how to deal with those different arguments.
Every call to virtual method could ve considered as code generation. In fact, there is at least one language, which implements virtual call with "select" statement.
24.05.2014 21:04 пользователь "Jesper Louis Andersen" <jesper.lou...@gmail.com> написал:
>
>
> On Sat, May 24, 2014 at 6:57 PM, Юрий Соколов <funny....@gmail.com> wrote:
>>
>> So that, it ought to use dispatch.
>
>
> It doesn't have to for polymorphic values. SML does need a dispatch for some implementations of functors however, but that is a different game altogether. The key is that a polymorphic value has no "methods" so to speak which can manipulate it. Thus you can pick a generic representation like a pointer (i.e., a box) and use that all over the place.
"Dispatch" doesn't mean "methods". Even "dynamic dispatch" doesn't mean "methods" nor "virtual methods". "Dispatch" is chosing implementation depending on actual arguments. "Methods" is just one form to declare "dispatching".
"Methods" doesn't mean "dynamic dispatch". Even "virtual methods" doesn't mean "dynamic dispatch" (in presence of whole program analyser).
>
> In a functor, you do need to know what structure you applied to it and there you have the distinction between dispatching or generation to a greater extent. Again, SML compilers pick different strategies. MLton expands functors through defunctorization, so it generates code. Again, it can do so because it is a whole program compiler[0]
>
I said same thing: there is only two ways to IMPLEMENT polymorphic code: either (dynamic) dispatch or code generation (static dispatch), or both combined. Semantically this ways are same.
24.05.2014 20:33 пользователь "chris dollin" <ehog....@googlemail.com> написал:
>
> On 24 May 2014 16:47, Юрий Соколов <funny....@gmail.com> wrote:
>> 24.05.2014 16:06 пользователь "chris dollin" <ehog....@googlemail.com> написал:
>>
>> There is only three ways to implement polymorphic functions: code generation, dinamyc dispatch, and interpretation.
>
> I don't think a typical SML implementation does any of those
> things for polymorphic functions. It just has a uniform size for
> data values (and an appropriate type system) -- hence large
> structures (for a small value of "large") are boxed.
So that, it ought to use dispatch.
>
> Note that SML's polymorphism is /parametric/ polymorphism,
> not OO-style polymorphism.Dispatch could like OO-style polimorphism, and could like not. It is still dispatch.
And still, it is just implementation details. Semantically, polimorphics are still code generation:
instead of writting function instance for each argument combination, you wrote rule to evaluator how to deal with those different arguments.
"Dispatch" is chosing implementation depending on actual arguments.
need not dispatch, or strictly, need only do a generic dispatch
I"m sadly only familiar with "boring angle bracket generics", ala Java/C++/C#, but I'm assuming you're talking about Scala/Haskell?
I said same thing: there is only two ways to IMPLEMENT polymorphic code: either (dynamic) dispatch or code generation (static dispatch), or both combined. Semantically this ways are same.
On Sat, May 24, 2014 at 7:24 PM, Юрий Соколов <funny....@gmail.com> wrote:
I said same thing: there is only two ways to IMPLEMENT polymorphic code: either (dynamic) dispatch or code generation (static dispatch), or both combined. Semantically this ways are same.
Indeed. And in a language like SML the parametric[0] polymorphism is such that you can often avoid a dispatch at all, because what you want statically holds. The SML functionfun len [] = 0| len (_ :: xs) = 1 + len xs
This ought to work with any kind of list content because we don't use the element for anything but its structure. If we do something along the lines of count = count + e.Value, then the type of the content becomes important, and likewise in SML. If we writefun len [] = 0| len (x :: xs) = x + (len xs)then the type is inferred to be int list -> int and the function isn't polymorphic anymore. No need for a dispatch here either.
fun sum [] = 0
| sum (x :: xs) = x + sum xs
??????? I could hardly imagine this function works without runtime dispatch or/and code generation.
Or may be SML doesn't allow instantiation of this function for both list of integer and list of float?
Then it is... ah... "limited polymorphism"
I said same thing: there is only two ways to IMPLEMENT polymorphic code: either (dynamic) dispatch or code generation (static dispatch), or both combined. Semantically this ways are same.