Solution

ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2017/functional-programming-design-and-analysis-of-algorithms/3/c/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.

New to topics? Read the docs here!