[Haskell-cafe] Re: ANNOUNCE: GHC survey results

Johannes Waldmann waldmann at imn.htwk-leipzig.de
Tue Jun 28 11:38:04 EDT 2005

Re:  Bulat's comments

> 1) adding OO-like features in O'Haskell style. for readers that don't
> know it's about adding new variants to ADT types:
> type Figure = Circle ...
> type Figure |= Box ...

With ADTs you do pattern match on the constructor,
but in OO style guides (see Fowler: Refactoring)
you find that "switch statements" are considered bad design.
Instead you would use the "Composite" design pattern

interface Figure
class Circle implements Figure
class Box implements Figure

this lets you add classes easily. Sure this is more verbose
but it might be easier to maintain and extend.
(Yes I know that mathematically a free algebra is a nice thing.)

> and adding new fields to existing records:
> type Point = {x,y::Int}
> type ColoredPoint = Point extended with {c::Color}

well I never would want to do that - and OO gurus do not recommend
it either. See Gamma et al, Design patterns, Introduction,
where they advise to use interface inheritance, but to avoid
implementation inheritance. This is exactly the situation
we have in Haskell.

Best regards,
-- Johannes Waldmann -- Tel/Fax (0341) 3076 6479/80 --
---- http://www.imn.htwk-leipzig.de/~waldmann/ -------

More information about the Haskell-Cafe mailing list