BlockML Documentation

Generic Types

Parameters that belong to their declaring Block

Generic parameters belong exclusively to the Block that declares them — never inherited implicitly — so a derived Block using a generic Block as baseType must account for every one of its parameters explicitly.

Declaring a generic parameter

A generic parameter is declared inside genericTypes as an element whose local name is the parameter itself, carrying a baseType constraint that every concrete argument at a reference site must satisfy.

Bind or forward — every base parameter must ground out

When a generic Block is used as baseType, the derived Block must bind each base parameter to a concrete type expression or forward it to a parameter declared locally — every parameter must eventually ground to a concrete type somewhere in the chain.

Binding a generic parameter through baseType

A generic Block declares one open parameter; a concrete specialization binds that parameter to a specific type through its baseType application.

<!-- Box declares one open parameter T, bounded by core:Block -->
<acme:Box xmlns="http://blockml.org/bml"
  xmlns:acme="com.acme.example"
  xmlns:core="org.blockml.bml.core">

  <baseType>
    core:Block
  </baseType>
  <genericTypes>
    <T baseType="core:Block" />
  </genericTypes>
  <properties>
    <item type="T" />
  </properties>
</acme:Box>

<!-- WidgetBox binds T to acme:Widget through its baseType application -->
<acme:WidgetBox xmlns="http://blockml.org/bml"
  xmlns:acme="com.acme.example">

  <baseType>
    acme:Box(acme:Widget)
  </baseType>
</acme:WidgetBox>

Box's item property is typed T, the still-open parameter; WidgetBox's baseType, acme:Box(acme:Widget), binds T to acme:Widget. That binding substitutes acme:Widget everywhere T appeared in Box's definition, so WidgetBox's own item property ends up typed acme:Widget, with no open parameters left.

What to carry into the next pages

After this page, readers should be able to declare, bind, or forward a generic parameter, closing out the type system group before the member model begins.

Continue with members