[Haskell-cafe] OO Design in Haskell Example (Draft)
Tim Docker
timd at macquarie.com.au
Sun Feb 25 18:26:44 EST 2007
Steve Downey wrote:
> So, I've been working on a Composite example. I've used
> existential types to have a generic proxy to the base
> type, rather than a simple algebraic type, since adding
> new leaves to the algebraic type means modifying the whole
> type, a violation of the Open-Closed principle (open for
> extension, closed for modification)
Rather than using existential types, a simple record of
functions can be often be useful. ie:
data Component = Component {
draw :: String
add :: Component -> Component
}
It might be worth comparing this approach with the (more
complex) one you have described.
Tim
More information about the Haskell-Cafe
mailing list