Hey Sebastiaan,<br><br>Generation of a single value (the leftmost), for instance, can be done as follows:<br><br><div style="margin-left: 40px;"><span style="font-family: courier new,monospace;">{-# OPTIONS_GHC -fglasgow-exts #-}</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">module Left where</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">import Generics.MultiRec.Base</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">class Left (phi :: * -&gt; *) (f :: (* -&gt; *) -&gt; * -&gt; *) where</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    leftf :: phi ix -&gt; (forall ix&#39;. El phi ix&#39; =&gt; phi ix&#39; -&gt; r ix&#39;) -&gt; [f r ix]</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    </span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">instance (Left phi a, Left phi b) =&gt; Left phi (a :+: b) where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    leftf w f = map L (leftf w f) ++ map R (leftf w f)</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">instance (Constructor c, Left phi f) =&gt; Left phi (C c f) where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    leftf w f = map C (leftf w f)</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">instance (Left phi a, Left phi b) =&gt; Left phi (a :*: b) where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    leftf w f = zipWith (:*:) (leftf w f) (leftf w f)</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">instance (El phi xi) =&gt; Left phi (I xi) where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    leftf _ f = [I (f index)]</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">instance Left phi U where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    leftf _ _ = [U]</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">instance (EqS phi, El phi ix, Left phi f) =&gt; Left phi (f :&gt;: ix) where</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    leftf w f =</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        case eqS (proof :: phi ix) w of</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            Nothing -&gt; []</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            Just Refl -&gt; map Tag (leftf w f)</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">instance LeftA a =&gt; Left phi (K a) where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    leftf _ _ = [K lefta]</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">class LeftA a where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    lefta :: a</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">instance LeftA Char where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    lefta = &#39;L&#39;</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">instance LeftA () where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    lefta = ()</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">left :: (El phi ix, Fam phi, Left phi (PF phi)) =&gt; phi ix -&gt; ix</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">left w = to w $ head $ leftf w (I0 . left)</span><br></div><br><br>I also have an arbitrary, but that&#39;s slightly more complex. Generic read should be available soon.<br>

<br>Cheers,<br>Pedro<br><br><div class="gmail_quote">On Mon, May 25, 2009 at 15:11, Sebastiaan Visser <span dir="ltr">&lt;<a href="mailto:sfvisser@cs.uu.nl" target="_blank">sfvisser@cs.uu.nl</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hey guys,<br>
<br>
While playing around with MultiRec most things are pretty straightforward and most usage can be derived from the examples. The only thing that seems tricky to do, and of which I cannot find any examples, are generic producers.<br>



<br>
Any examples of generic producers that take no values as input but do produce values as output? E.g. generic parsers (read), binary get, arbitrary?<br>
<br>
I have some `SingleRec&#39; producers that are fairly trivial to port except for the `Tag&#39; case. Any clues?<br>
<br>
Thanks,<br><font color="#888888">
<br>
--<br>
Sebastiaan Visser<br>
<br>
_______________________________________________<br>
Generics mailing list<br>
<a href="mailto:Generics@haskell.org" target="_blank">Generics@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/generics" target="_blank">http://www.haskell.org/mailman/listinfo/generics</a><br>
</font></blockquote></div><br>