Is there a visual modeling language or style for the functional programming paradigm?

See archived version with outlinks here.

As of May 26, 2023, there is no standard modeling language for pure functional programming, but there are alternatives:

1. UML

UML has traditionally been associated with object-oriented programming (OOP), mostly because of its historical roots1, 2, but one can certainly attempt to use it for different programming paradigms (or for something other than modeling software, for that matter, such as use-case diagrams, ontology engineering, manufacture and other systems & processes, etc.).

With that said, there don’t seem to be many examples around for this use case. A noteworthy few:

The answers above mention that there are UML diagram types other than class diagrams, whose use would benefit any program, independent of paradigm. See 1 and the Modeling applications of UML using various diagrams section of the Applications of UML wikipedia page, along with a diagram:

Hierarchy of diagrams in UML 2.2
source

[1]: UML Diagrams: History, Types, Characteristics, Versions, Tools
[2]: https://stackoverflow.com/a/27861475/1498178

1.1 Statecharts

From the Statecharts: a visual formalism for complex systems paper:

[statecharts] extend conventional state-transition diagrams with essentially three elements, dealing, respectively, with the notions of hierarchy, concurrency and communication. These transform the language of state diagrams into a highly structured and economical
description language.

If the program doesn’t deal with state, then this is not very useful but it seems to be a noteworthy tool otherwise.

More info and discussions:

2. Diagrams

2.1 Wiring diagram

From Seven Sketches in Compositionality: An Invitation to Applied Category Theory, section 2.2.2 Introducing wiring diagrams:

Wiring diagrams are visual representations for building new relationships from old.

Examples:

  • enter image description here
  • enter image description here

2.2 String diagram

Seven Sketches in Compositionality: An Invitation to Applied Category Theory mentions string diagrams, but they seem to be different from wiring diagrams. From the paper Category Theory Using String Diagrams:

String diagrams are a graphical formalism for working in category theory, providing a convenient tool for describing morphisms within bicategories [B ́enabou, 1967], some background on string diagrams can be found in [Street, 1995].

A visual proof as a string diagram

2.3 Data flow diagrams

This section expands on this answer.

2.3.1 “Henderson diagram”

These show how individual functions are “plugged together”“. From section 3.5.2 Infinite Streams of SICP:

Figure 3.31: The prime sieve viewed as a signal-processing system.

2.3.2 Diagrams used in the Arrows documentation

enter image description here

class Arrow a where
  arr :: (b -> c) -> a b c
-- Each function may be treated as
 a computation.

enter image description here

  (>>>) :: a b c -> a c d -> a b d
-- Computations may be composed, by
-- connecting the output of the first
-- to the input of the second.

enter image description here

  first :: a b c -> a (b,d) (c,d)
-- A computation may be applied to part
-- of the input, with the rest copied
-- through to the output.

enter image description here

2.4 Hasse diagram (wikipedia)

Category theory is all about organizing and layering structures3 so Hasse diagrams may be useful. A UML class diagram is “a form of Hasse diagram“, so it can be used in a more general sense to convey dependency relations.

[3] Seven Sketches in Compositionality: An Invitation to Applied Category Theory, section
“1.1.2 Ordering systems”

2.5 Commutative diagram (wikipedia)

These can be used to describe how functions and structures interact with each other; however, they rather define invariants/laws than behaviour.

Examples:

3. Formal methods

3.1 Universal Systems Language (USL) (proprietary?)

Universal systems language (USL) is a systems modeling language and formal method for the specification and design of software and other complex systems. It was designed by Margaret Hamilton based on her experiences writing flight software for the Apollo program. The language is implemented through the 001 Tool Suite software by Hamilton Technologies, Inc.

See articles on Hamilton Technologies, Inc.’s homepage.

3.2 TLA+

TLA+ is a formal specification language developed by Leslie Lamport. It is used for designing, modeling, documentation, and verification of programs, especially concurrent systems and distributed systems.

It felt prudent to mention TLA+ here as well.

4. Tools

4.1 ghc-vis

Similar to Python Tutor,

ghc-vis is a tool to visualize live Haskell data structures in GHCi. Evaluation is not forced and you can interact with the visualized data structures. This allows seeing Haskell’s lazy evaluation and sharing in action

Visualization of the execution of a Haskell program

4.2 Visual Haskell

This thesis presents and justifies a framework for programming real-time signal processing systems. The framework extends the existing “block-diagram” programming model; it has three components: a very high-level textual language, a visual language, and the dataflow process network model of computation.

From section 4.2 An introduction to Visual Haskell:

The factorial function in Visual Haskell

4.3 Viskell (tool; last commit: 2017)

Viskell is an experimental visual programming environment for a typed (Haskell-like) functional programming language. This project is exploring the possibilities and challenges of interactive visual programming in combination with the strengths and weaknesses of functional languages.

Screenshot of Viskell's user interface

4.4 graphmod Haskell package

Present the module dependencies of a program as a “dot” graph.

4.5 HOPS: The Higher Object Programming System

HOPS is a graphically interactive program development and program transformation system based on term graphs.

Seems unmaintained, but looked interesting.

enter image description here
See more images / animations here.


Other interesting resources:

Leave a Comment