[Haskell] Trying to get a Composite design pattern to work

ajb at spamcop.net ajb at spamcop.net
Mon Mar 13 20:49:36 EST 2006

G'day all.

Quoting Asfand Yar Qazi <ayqazi at gmail.com>:

> Actually, I'm trying to avoid library functions, so I can learn the
> language and the functional way of thinking.  How would one implement
> the concatMap function?

See if you can work how how this one works.  No library functions, apart
from function composition.

statesList :: StateNode a -> [a]
statesList s
  = statesList' s []
    statesList' (State x) = (x:)
    statesList' (CompositeState xs) = statesLists xs

    statesLists [] = id
    statesLists (x:xs) = statesList' x . statesLists xs

Andrew Bromage

More information about the Haskell mailing list