Feature Kinds
A major design goal of Fuzion is to unify different concepts into the single
concept of a Fuzion feature. This makes a Fuzion feature a very powerful
mechanism. Nevertheless, Fuzion features are not all the same, there are
different kinds of features and what can be done with one feature might not be
possible with a different kind of feature. The following table gives an overview
of what can be done with features of different kinds.
But first, let's see what all features have in common
What all features have in common
Feature name
All features declared in Fuzion have a feature name. The name is typically
just an identifier such as execute
, or an operand such
as postfix !
.
Feature nesting
All features are declared within the context of an outer feature. This outer
feature is the feature that syntactically surrounds the feature
declaration. In case there is no explicit feature surrounding a feature
declaration, the outer feature is an implicit feature called universe
.
Differences between Feature Kinds
Fuzion Features are of one of several kinds and not all features can be used
in every context. This gives an overview of the feature kinds and what they can
do.
Examples
Defining a Type
Constructor
One restriction is that type names must not be ambiguous.
Overloading of constructors results in the corresponding types to be no longer
usable since Fuzion does not permit a means to disambiguate overloaded types:
Routine
A routine does define a type, but this type is anonymous. It does not
have a name that we could use in a declaration. However, type inference can be
used to create features using a routine's type:
An instance of a routine's implicit type can even exist longer than the
routine's call itself. Here is an example that shows a routine in a closure
that extends the life span of the routine's instance until after the call to the
routine has returned:
Negative example: Using a routine's name explicitly as a type does not work
since a routine does not define a name for its type:
Field
Intrinsic
Abstract
Choice
Containing code
Constructor
Routine
Field
Intrinsic
Abstract
Choice
Containing declarations
Constructor
Routine
Field
Intrinsic
Abstract
Choice
Positive example declarations:
Negative example declaring a field:
Being redefined
Constructor
Routine
Field
Intrinsic
Abstract
Choice
Redefining
Constructor
Negative example with compatible types that could be permitted, but is forbidden:
Negative example with incompatible types:
Routine
Field
Intrinsic
Abstract
Choice
Having formal arguments
Constructor
Routine
Field
Intrinsic
Abstract
Choice
Having explicit result type
Constructor
Routine
Field
Intrinsic
Abstract
Choice
Having formal type arguments
Constructor
Routine
Field
Intrinsic
Abstract
Choice
Being called
Constructor
Routine
Field
Intrinsic
Abstract
Choice
Being assigned to
Constructor
Routine
Field
Intrinsic
Abstract
Choice
Being target of inheritance call
Constructor
Routine
Field
Intrinsic
Abstract
Choice
May inherit
Constructor
Routine
Field
Intrinsic
Abstract
Choice