Closed lucaswerkmeister closed 10 years ago
Okay, I think I’ve got a good solution. I’ll explain it on the example of CaseTypes
:
caseTypes
function which takes only CaseTypesIsh
.If you already have a caseTypes
object, just use it directly. And I don’t think users should ever have values of type CaseTypes|CaseTypesIsh
.CaseTypes|CaseTypesIsh
, used by the other functions.caseTypes
aren’t the last parameter, declare parameter type CaseTypes|CaseTypesIsh
, and use the internal function.This allows
value cd = classDefinition {
// ...
caseTypes = { "true", "false" };
// ...
}
as well as
value cd = classDefinition {
// ...
caseTypes = selfCaseTypes;
// ...
}
and
value ct = caseTypes {
for (i in 1:nStates)
"S``i``"
}
In general, however, it must be noted that in ceylon.ast.create
, the idea of “one pattern fits all” must be abandoned, and other kinds of nodes will require different treatment.
Actually… let’s make the caseTypes
etc. functions variadic.
…that will require us to remove the Absent
trick, at least from the shared function. Which is okay – it’s more used for internals, I think.
At the moment, we define the -
Ish
aliases like this:I. e.,
BodyIsh
includesBody
. The rationale behind this is that if you already have aBody
object from somewhere, you should be able to use it in the create functions.However, that prevents the use of the following syntax:
Because this is only supported “if the parameter list has an unassigned parameter of type exactly
Iterable<T,N>
for some typesT
andN
”, i. e., ifBodyIsh
was just{Declaration|Statement*}
.Should we make the aliases “non-reflexive”? I think the named arguments syntax would be a pretty big advantage…