I have been working on a business data model for my WPF demo application (which I hope to begin describing soon). One of my requirements for this was a nested data structure to model a namespace hierarchy. Doing this in an imperative way was easy but my goal was to use immutable data structures to support a functional-programming approach to the data. Eventually, I settled on a nested Map structure with an F# record data type to represent the underlying data. Structurally, this was similar to how I would have approached it from an imperative perspective, but this was after several other attempts using custom data structures (abstract syntax trees and other approaches) had proven too inflexible to the demands of the application.
A second requirement for this data structure was abstraction. I did not want the internal data structure to be exposed to client code. Therefore, I needed to provide custom enumeration support. This post describes two approaches to this.