-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
should the trait shortcut permit non-type parameters? #58
Comments
I'm not clear what point the above program is intended to illustrate. As I though I had posted here already (but can't now find!), the issue is not traits taking parameters, but traits being given non-manifest arguments. We agreed at Pomona that traits should be manifest. That should mean that either they don't have parameters at all, or that any (type or object) parameters they do have must be instantiated with manifest arguments. So I answer the question in the issue title affirmatively. But the trait instantiations above are still illegal. |
I recall (from Michael's explanation in the teleconference) that the rules on not having code or state in traits can be surmounted with these kinds of constructions.
I don't see any non-manifest arguments in the above example - but I'm not sure what definition of manifest you are using! Talking to Michael this afternoon, we got to something like the structure of the a manifest expression can be determined before any code starts running. I think that applies here.
Why? I'm not trolling: I'm just not sure which instantiations you consider illegal, and why |
I broke the initial example into two separate examples. Presumably, these are trying to illustrate separate things. Something bad happens, right? Could you please explain what the bad thing is in the first example. We know that we can have (hidden) state in a trait — that's a deliberate design choice. That's why we designate the object produced by method uid {
def myuid = Singleton.new
object { // meets the restrictions to be trait object
method uid { myuid }
}
} as being a trait. In the second example, the bad thing is that the trait composition of
doesn't look manifest to me. |
from a brief talk to Micahel, I think that is the "bad thing" in the first example
if "manifest" means the "shape" of the final result can be determined before the code really starts running, or that the code does not depend on mutable state, including input then that code, while rather ugly, would be manifest. |
I don't understand either of your points above. We do allow implicit state; I don't know what "mutable code" is. Let's leave this for the teleconference. |
This seems to have devolved into a discussion of manifest, which is in #47. This is just a detail of the "traits shortcut". Should non-type parameters be permitted? |
It would seem inconsistent not to support type parameters in the trait shortcut, since once can get the same effect using a method that has a parameter, and whose body is an object constructor that captures the parameter and meets the trait restrictions. However, @kjx and Michael Homer seem to have examples that show that parameters are problematic. I'm therefore reluctant to make a decision until someone explains what the problem is. Hence, my desire to leave this for the teleconference. |
We have to support type parameters in the trait shortcut (or otherwise we have to give up on (generic) static typing; give up on traits; or just give up). The question is whether we support non-type parameters.
The presenting problem is that parameters offer yet another way to arrange "traits" that have state and complex stateful initialisation semantics, as per the examples above. The underlying problem is that if traits have state and complex stateful initialisation semantics, why do we now have two inheritance-like mechanisms and two class-like shortcuts instead of just one of each? |
I prefer only type parameters to traits. Kim
|
If Andrew's happy with that then I guess we can accept and move on. Or we could consider
For example, given the following principles:
Then the answers would be:
|
drafted to say classes and traits are parallel |
I'm not quite sure why trait expressions are generative (i.e., more like classes than objects). There is no initialization code, so no need to generate a fresh trait object. I see the main distinctions between traits and objects in terms of what traits are missing:
|
yes, that's right. and we can say that either way
three reasons for me:
|
OK, let's give it a try that way. |
I'm never sure what @kjx means when he says "generative". Object constructors are "generative" in the sense that they make a new object every time they are executed. That object can capture the lexical bindings that applied at the time of its creation. So a type variable used within the trait object might take on different values each time the trait object constructor is executed. But I think that you want something more than that for traits. As you say, you want them to be parameterizable. That's why, I thought, you wanted the trait syntax to correspond to a method that creates a trait object. That's two levels of generation! What about type definitions? Type definitions with parameters? Are they "generative"? In what sense? |
@KimBruce - phew! good! @apblack generative = makes a 'new' object each time, for suitable def of new object (especially where values are concerned)
I think they have to be, in that the (conceptually) generate 'new' objects every time. |
|
|
Here is a variable in a trait:
Here is a side effect:
The text was updated successfully, but these errors were encountered: