<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<title></title>
</head>
<body>
Hi all,<br />
<br />
thanks for your ideas so far.<br />
<br />
> I think you might be looking for too much sugar.  I don't know much<br />
> about your problem, but I would use approximately your approach and be<br />
> straightforward:<br />
<br />
To bother you with some details: i am building a model for an SVG document.<br />
<a href="http://chlor.svn.sourceforge.net/viewvc/chlor/trunk/haskell/Chlor/FileFormat/Svg/SvgDocument.hs">http://chlor.svn.sourceforge.net/viewvc/chlor/trunk/haskell/Chlor/FileFormat/Svg/SvgDocument.hs</a><br />
<br />
There are many SVG elements, of which only a few are valid as the content of each other SVG elements.<br />
SvgDocumentElement defines the allowed subset for the SVG document.<br />
<br />
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.<br />
So it's a bit more complicated than your "Either" example<br />
<br />
I need to manually efine such subset data structures for most SVG elements which does not feel most elegant already.<br />
Additionally instantiating a class for the subset structures, in order to being able to iterate over them, feels even more clumsy.<br />
<br />
So i wonder whether i am missing a more clean approach to the problem "easily combining data structures but also easy iteration over them".<br />
<br />
> <br />
> type SubSet = Either A C<br />
> <br />
> > and use it in Foo:<br />
> ><br />
> >     data Foo = Foo [SubSet]<br />
> ><br />
> > No i want to perform a polymorphic operation on the contents of A,B,C, e.g.<br />
> ><br />
> > doSomething :: Foo -> [Double]<br />
> > doSomething (Foo s) = map doSomethingElse s<br />
> <br />
> doSomething (Foo s) = map (doSomethingWithA ||| doSomethingWithC) s<br />
> <br />
> (||| is from Control.Arrow)<br />
> <br />
> If that gets too complicated, you can build the "doSomething"<br />
> functions in a type-directed way using typeclasses:<br />
> <br />
> class DoSomething a where<br />
>     doSomething :: a -> Double<br />
> <br />
> instance DoSomething A where ...<br />
> instance DoSomething B where ...<br />
> instance DoSomething C where ...<br />
> <br />
> instance (DoSomething a, DoSomething b) => DoSomething (Either a b) where<br />
>     doSomething = doSomething ||| doSomething<br />
> <br />
> Luke<br />
</body>
</html>