liveBook · Manning

ComponentDef

As explained in Functional Design and Architecture: Examples in Haskell

ComponentDef is a book-specific data type representing a component definition or blueprint in an Hdl specification.

ComponentDef is a declarative Hdl definition: a blueprint that pairs a component index with its ComponentPassport. An Hdl specification is a list of these definitions. section 4.1.3

The initial design used separate Sensor and Controller constructors and repeated classification data in both ComponentDef and ComponentPassport. That duplication allowed contradictory values, such as a sensor passport attached to a controller definition. section 3.3.2 section 4.1.2

The refactored representation keeps responsibilities separate:

  • ComponentPassport describes what a vendor component is, including its class, name, GUID, and vendor. section 3.3.2
  • ComponentDef describes where that component belongs in the Hdl specification by storing its ComponentIndex and passport. section 4.1.3
  • ComponentClass carries sensor-specific information such as Temperature or Pressure, removing the need for specialized ComponentDef constructors. section 4.1.2 section 4.1.3

A booster definition

A booster Hdl specification can declare entries such as ComponentDef "nozzle1-t" aaaTemperature25Passport and ComponentDef "controller" aaaController86Passport. Later, makeDevice validates each passport against available VendorComponents before inserting the resulting DevicePart under its index. section 4.1.3

Listing 3.9 HDL for device definitions
module Andromeda.Hardware.Common where         #1
  
type PhysicalGuid  = String                    #2
type ComponentName = String                    #3
  
data Parameter      = Temperature | Pressure   
data ComponentClass = Sensors | Controllers
type Vendor         = String
  
data ComponentPassport = ComponentPassport
  { componentClass  :: ComponentClass
  , componentName   :: ComponentName
  , componentGuid   :: PhysicalGuid
  , componentVendor :: Vendor
  }
 
  
module Andromeda.Hardware.Hdl where            #4
  
import Andromeda.Hardware.Common               #5
  
type ComponentIndex = String
  
data ComponentDef
  = Sensor     ComponentPassport ComponentIndex Parameter 
  | Controller ComponentPassport ComponentIndex
  
type Hdl = [ComponentDef]                      #6

The listing shows the original algebraic design, including ComponentPassport, ComponentDef constructors, and Hdl as a list of component definitions. section 3.3.2

How Functional Design and Architecture: Examples in Haskell covers it

How deep it goes
Explains the representation, its inconsistency risks, and its refactoring into an index-and-passport form; it defers implementation state.
Examples
Uses booster definitions, vendor passports, nozzle indexes, smart constructors, and validation while assembling a Device.
What it assumes
Assumes algebraic data types, records, lists, maps, and functional module boundaries while teaching the domain model from device definitions.
What you can do after
Build it from scratch by declaring indexed components, associating vendor passports, and passing the Hdl specification to device construction.
How it connects
Connects ComponentDef with Hdl, ComponentPassport, ComponentClass, VendorComponent, Device, smart constructors, and the interpreter.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Design and Architecture: Examples in Haskell. The section links point to the parts of the book it draws on.