[Haskell-cafe] Design question

haskell at kudling.de haskell at kudling.de
Thu Dec 17 06:44:12 EST 2009

Hi all,

thanks for your ideas so far.

> I think you might be looking for too much sugar.  I don't know much
> about your problem, but I would use approximately your approach and be
> straightforward:

To bother you with some details: i am building a model for an SVG document.

There are many SVG elements, of which only a few are valid as the content of
each other SVG elements.
SvgDocumentElement defines the allowed subset for the SVG document.

I want to generate a "DList Char" for all those sub-elements and finally
collapse them to one "DList Char" representing the whole SVG document.
So it's a bit more complicated than your "Either" example

I need to manually efine such subset data structures for most SVG elements which
does not feel most elegant already.
Additionally instantiating a class for the subset structures, in order to being
able to iterate over them, feels even more clumsy.

So i wonder whether i am missing a more clean approach to the problem "easily
combining data structures but also easy iteration over them".

> type SubSet = Either A C
> > and use it in Foo:
> >
> >     data Foo = Foo [SubSet]
> >
> > No i want to perform a polymorphic operation on the contents of A,B,C, e.g.
> >
> > doSomething :: Foo -> [Double]
> > doSomething (Foo s) = map doSomethingElse s
> doSomething (Foo s) = map (doSomethingWithA ||| doSomethingWithC) s
> (||| is from Control.Arrow)
> If that gets too complicated, you can build the "doSomething"
> functions in a type-directed way using typeclasses:
> class DoSomething a where
>     doSomething :: a -> Double
> instance DoSomething A where ...
> instance DoSomething B where ...
> instance DoSomething C where ...
> instance (DoSomething a, DoSomething b) => DoSomething (Either a b) where
>     doSomething = doSomething ||| doSomething
> Luke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091217/d8998c11/attachment.html

More information about the Haskell-Cafe mailing list