Solution (source code)

= Solution

First enumerate each possible row, then choose one row from each row's alternatives:

``
expand :: Matrix [a] -> [Matrix a]
expand = cp . map cp
``

The inner <Cartesian product> converts one row of cell choices into its possible rows; the outer product combines those rows into whole <matrices>. Every assignment is represented exactly once when each cell's alternatives are distinct. Empty cell domains yield no grids, and an empty matrix yields the singleton list containing the empty matrix.