<!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 />
    &gt; I think you might be looking for too much sugar.&#160; I don&#39;t know much<br />
    &gt; about your problem, but I would use approximately your approach and be<br />
    &gt; 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&#160;want to generate a &quot;DList Char&quot; for all those sub-elements and finally collapse them to one &quot;DList Char&quot; representing the whole SVG document.<br />
    So it&#39;s a bit more complicated than your &quot;Either&quot; 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,&#160;feels even more clumsy.<br />
    <br />
    So i wonder whether i am missing a more clean approach to the problem &quot;easily combining data structures but also easy iteration over them&quot;.<br />
    <br />
    &gt; <br />
    &gt; type SubSet = Either A C<br />
    &gt; <br />
    &gt; &gt; and use it in Foo:<br />
    &gt; &gt;<br />
    &gt; &gt; &#160;&#160;&#160; data Foo = Foo [SubSet]<br />
    &gt; &gt;<br />
    &gt; &gt; No i want to perform a polymorphic operation on the contents of A,B,C, e.g.<br />
    &gt; &gt;<br />
    &gt; &gt; doSomething&#160;:: Foo&#160;-&gt; [Double]<br />
    &gt; &gt; doSomething&#160;(Foo s) = map doSomethingElse&#160;s<br />
    &gt; <br />
    &gt; doSomething (Foo s) = map (doSomethingWithA ||| doSomethingWithC) s<br />
    &gt; <br />
    &gt; (||| is from Control.Arrow)<br />
    &gt; <br />
    &gt; If that gets too complicated, you can build the &quot;doSomething&quot;<br />
    &gt; functions in a type-directed way using typeclasses:<br />
    &gt; <br />
    &gt; class DoSomething a where<br />
    &gt;&#160; &#160; &#160;doSomething :: a -&gt; Double<br />
    &gt; <br />
    &gt; instance DoSomething A where ...<br />
    &gt; instance DoSomething B where ...<br />
    &gt; instance DoSomething C where ...<br />
    &gt; <br />
    &gt; instance (DoSomething a, DoSomething b) =&gt; DoSomething (Either a b) where<br />
    &gt;&#160; &#160; &#160;doSomething = doSomething ||| doSomething<br />
    &gt; <br />
    &gt; Luke<br />
  </body>
</html>