Hylo Language Specification — Trait conformance (section excerpt)
Trait conformance
-
A type
Aconforms to a traitT1in a lexical scope if a conformance ofAtoT1is exposed to that scope and ifT1and satisfies all the requirements ofT1, or ifAconforms to a traitT2such thatT2refinesT1. -
(Example)
trait T { fun foo() } trait U { fun bar() } // declares conformance to 'T' type A: T {} // satisfies conformance to 'T' extension A { fun foo() {} } // declares and satisfies conformance to 'U' conformance A: U { public fun bar() {} } -
A source of conformance denotes a declaration defining the conformance of a type to a trait. A type or conformance declaration is a source of conformance for all the traits that appear in its inheritance list. A source of conformance is conditional if it is a conformance declaration with a where clause. A type may have at most one source of conformance to a specific trait. A type that conforms to a trait
T1shall not have a source of conformance to a traitT2ifT2refinesT1and the source of conformance toT1is conditional. -
The conformance of a type
AtoTis exposed to a lexical scopelif and only ifAis exposed toland the source of the conformance is: -
the declaration of
A; or -
a conformance declaration declared in
lor a lexical scope that containsl; or -
an external conformance declaration imported from another module.
-
The conformance of a type
Ato a traitTshall not be exposed outside of the lexical scope of a modulemunless at leastAorTis declared inm. -
(Example)
import M public type A {} conformance A: M.T {} // OK: conformance is private type B: M.T {} // OK: 'B' is not exposed outside of the module public type C: M.T {} // error: cannot expose conformance to imported trait 'M.T' -
A method requirement
ris satisfied if by a typeAifAhas a single methodmwith the same name, type, and kind.mmay be defined in the type declaration, extension declaration, or a conformance declaration ofA. Ifrhas default implementations, it may be satisfied byAif there exists a unique default implementation whose conditions are satisfied byA.