liveBook · Manning

Mnemonic analysis

As explained in Functional Design and Architecture: Examples in Haskell

Mnemonic analysis is a domain-analysis technique that transforms a scenario into a more formal representation to reveal internal domain properties.

Mnemonic analysis transforms a domain scenario into a more formal representation to expose internal behavior and guide a domain-specific language. The scenario remains readable enough for nondevelopers while making variables, conditions, APIs, and responsibilities explicit. section 3.1.4 section 3.4

Apply the technique by exploring alternative representations rather than accepting the first imperative formulation:

  • Write a realistic scenario in a readable pseudolanguage, including inputs, timing, branches, subroutines, and external effects. section 3.1.4
  • Identify the domain behavior: read a sensor, classify the value against bounds, store measurements, log failures, and raise alarms. section 3.1.4
  • Rework the same behavior as a stream of readings, separating acquisition, conversion, storage, validation, and alerting. section 3.1.4
  • Compare the representations to discover a form suitable for an external or internal domain-specific language. section 3.1.4

Temperature monitoring

A thermometer scenario reads once per second, records time, temperature, and device, converts Celsius to Kelvin, stores valid readings, and logs or alarms on out-of-range values. A stream-based version yields readings to a monitor, which validates them and returns either success or a failure message. section 3.1.4

Listing 3.3 Temperature sensor readings scenario
Scenario: readThermometer                               #1
Description: monitor outside thermometer temperature
Given: outside thermometer @therm
Invocation: once a second
  
  Read @therm,                                          #2
    Result: @reading(@time, @temp, @therm)
  
  If @temp < -10C Then                                  #3
    register @reading                                   #4
    Log @reading                                        #5
    Raise alarm "Temperature is too low"                #6
 
  Else If @temp > 50C Then                              #7
    register @reading 
    Log @reading 
    Raise alarm "Temperature is too high"
  
  Else register @reading                                #8
  
  Return @reading                                       #9

Inspect the readable sensor scenario and its explicit branches, effects, and returned reading. section 3.1.4

How Functional Design and Architecture: Examples in Haskell covers it

How deep it goes
Compares imperative and stream-based representations, but stops short of defining a finished language implementation.
Examples
Uses spacecraft thermometer readings, Kelvin conversion, database storage, logging, alarms, and stream-based validation.
What you can do after
Evaluate domain behavior and select a more suitable formal representation for an internal or external domain-specific language.
How it connects
Connects domain-specific languages with imperative programming, reactive streams, validation, persistence, and external APIs.

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.