<div dir="ltr"><font face="arial, helvetica, sans-serif">It got a lot easier when I forgot all about the monads:</font><div><font face="arial, helvetica, sans-serif"><br></font></div><div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace">type SaState = ( P2, CircleFrac, Double )</font></div><div><font face="courier new, monospace">type SaPic =   ( (Trail R2), (Trail R2) )</font></div><div><font face="courier new, monospace">type SaWorld = ( SaPic, SaState )</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">type SaAct = SaState -&gt; SaWorld</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">bigbang :: Double -&gt; SaWorld</font></div>
<div><font face="courier new, monospace">bigbang w = ((mempty,mempty), (origin,0,w))</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">(&gt;%) :: SaWorld -&gt; SaAct -&gt; SaWorld</font></div>
<div><font face="courier new, monospace">((t1,b1),s1) &gt;% f = let ((t2,b2),s2) = f s1 in ((t1&lt;&gt;t2,b2&lt;&gt;b1),s2)</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">(&gt;%=) :: SaAct -&gt; SaAct -&gt; SaAct</font></div>
<div><font face="courier new, monospace">f &gt;%= g = \s1 -&gt; </font></div><div><font face="courier new, monospace">  let ((t2,b2),s2) = f s1 in  </font></div><div><font face="courier new, monospace">  let ((t3,b3),s3) = g s2 in</font></div>
<div><font face="courier new, monospace">  ((t2&lt;&gt;t3,b3&lt;&gt;b2),s3)</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">saVia :: Double -&gt; SaAct</font></div>
<div><font face="courier new, monospace">saVia l (p,a,w) = </font></div><div><font face="courier new, monospace">  (</font></div><div><font face="courier new, monospace">    ( hrule l # translateX (l/2) # translateY (w/2) # rotate a </font></div>
<div><font face="courier new, monospace">    , hrule (-l) # translateX (l/2) # translateY (-w/2) # rotate a </font></div><div><font face="courier new, monospace">    )</font></div><div><font face="courier new, monospace">    ,</font></div>
<div><font face="courier new, monospace">    (p .+^ (unitX # scale l # rotate a),a,w)</font></div><div><font face="courier new, monospace">  )</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">saTo :: SaAct</font></div>
<div><font face="courier new, monospace">saTo (p,a,w) = </font></div><div><font face="courier new, monospace">  (</font></div><div><font face="courier new, monospace">    ( hrule   w  # translateX (-w/2) # rotate (-0.125 :: CircleFrac) # scale 0.7071 # translateX (w/2) # rotate a # translate (origin .-. p)</font></div>
<div><font face="courier new, monospace">    , hrule (-w) # translateX (-w/2) # rotate ( 0.125 :: CircleFrac) # scale 0.7071 # translateX (w/2) # rotate a # translate (origin .-. p)</font></div><div><font face="courier new, monospace">    )</font></div>
<div><font face="courier new, monospace">    ,</font></div><div><font face="courier new, monospace">    (p,a,0)</font></div><div><font face="courier new, monospace">  )</font></div><div><font face="courier new, monospace">   </font></div>
<div><font face="courier new, monospace">saTurn :: Double -&gt; CircleFrac -&gt; SaAct</font></div><div><font face="courier new, monospace">saTurn r a&#39; (p,a,w) = let (outr, inr, qu) = if a&#39;&gt;=0 then (r, -w-r, -0.25::CircleFrac) else (-w-r, r, 0.25::CircleFrac) in</font></div>
<div><font face="courier new, monospace">  (</font></div><div><font face="courier new, monospace">    ( arc&#39; outr (a+qu) (a+a&#39;+qu)  # translate (unitY # rotate (a+a&#39; )# scale w)</font></div><div><font face="courier new, monospace">    , arc&#39; inr  (a+a&#39;+qu) (a+qu) # translate (unitY # rotate (a+a&#39; )# scale w)</font></div>
<div><font face="courier new, monospace">    )</font></div><div><font face="courier new, monospace">    ,</font></div><div><font face="courier new, monospace">    (p,a+a&#39;,w)</font></div><div><font face="courier new, monospace">  )</font></div>
<div><font face="courier new, monospace">   </font></div><div><font face="courier new, monospace">saSplit :: [(Double, SaAct)] -&gt; SaAct</font></div><div><font face="courier new, monospace">saSplit fs (p,a,w) =</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>let (placed,_) = ( foldl ( \(l,t) -&gt; \(i,f) -&gt; ( l++[( ( p .+^ (unitY # rotate a # scale (((t+i/2)-0.5)*w)), a, w*i) ,f )],t+i) ) ([],0) fs ) in </font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>let ws = map (\(b,f)-&gt; f b) placed in</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>((foldl (&lt;&gt;) mempty (map (\((tt,bb),_)-&gt;tt&lt;&gt;bb) ws),mempty),(origin,0,0))</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">p3 = bigbang 5 &gt;% (saVia 10 &gt;%= (saSplit </font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>[ (0.80,(saVia 10 &gt;%= saTo))</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>, (0.20,saTurn 1 (-0.25) &gt;%= (saVia 2 &gt;%= (saSplit </font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                </span>[ (0.10,saTurn 1 (0.25) &gt;%= (saVia 5 &gt;%= saTo))</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre">                </span>, (0.80,(saVia 3 &gt;%= saTo))</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                </span>, (0.10,saTurn 1 (-0.25) &gt;%= (saVia 5 &gt;%= saTo))</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre">                </span>] )))</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>] ))</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace">pic3 = let p = fst $ p3 in</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>(strokeT $ close $ (fst p) &lt;&gt; (snd p) ) # fc red </font></div>
<div><br></div></div><div><br></div><div style>But still I feel I&#39;m missing something. </div><div style><br></div><div style>Adrian.</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On 1 June 2013 00:31, Adrian May <span dir="ltr">&lt;<a href="mailto:adrian.alexander.may@gmail.com" target="_blank">adrian.alexander.may@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Thanks, but I still don&#39;t know how to fix it.<div><br></div><div>In the meantime, I&#39;m struggling with something more basic. I plan to write a basic monad that puts diagrams on top of each other, then I&#39;ll let State take care of pushing the origin and angle along (turtle style). But I&#39;m already stuck on that basic monad.</div>

<div><br></div><div>It&#39;s &gt;&gt;= has to explicitly use the fact that each monad has a journey there and a journey back. The thing on the right of &gt;&gt;= will be inserted in between them.  But I always get either &quot;something is a rigidly bound type variable&quot; or &quot;Monad should have kind * -&gt; *&quot; </div>

<div><br></div><div>I just don&#39;t know how this is supposed to work.</div><div><br></div><div>I want the monad to contain two trails, in the sense of the Diagrams module. If I bind two of them together, for the time being, I&#39;ll just stick them on top of each other (at least I think the State monad will rescue me from that.) I have no particular reason to tell the thing on the right of &gt;&gt;= about the thing on the left. Neither do I have a reason for &gt;&gt;= to be polymorphic. </div>

<div><br></div><div>Right now I&#39;m thinking that I&#39;ll have to define a class for things that provide a journey there and a journey back. I&#39;d rather not, because there&#39;s only one of them but I can&#39;t seem to restrict the game any other way, but this way isn&#39;t helping either.</div>

<div><br></div><div>Ideally I&#39;d be able to write something like this:</div><div><br></div><div><font face="courier new, monospace">data Sankey = Sankey {there, back :: Trail R2}</font></div><div>
<font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">instance Monad Sankey where</font></div><div><font face="courier new, monospace">  return t b = Sankey t b</font></div>
<div><font face="courier new, monospace">  l@(Sankey t b) &gt;&gt;= f = let (Sankey t&#39; b&#39;) = f l in</font></div><div><font face="courier new, monospace">     Sankey (t &lt;&gt; t&#39;) (b &lt;&gt; b&#39;)</font></div>

<div><font face="courier new, monospace"><br></font></div><div>although I have no reason to pass l to f. But the compiler barfs anyway. I feel that Haskell is more complicated than what I&#39;m trying to do. Under duress I tried:</div>

<div><br></div><div><div><font face="courier new, monospace">class Pic a where </font></div><div><font face="courier new, monospace">  there :: a -&gt; Trail R2</font></div><div><font face="courier new, monospace">  back  :: a -&gt; Trail R2</font></div>

<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">data Trails p = Trails p   </font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">instance (Pic p) =&gt; Monad (Trails p) where </font></div>

<div><font face="courier new, monospace">  return = Trails </font></div><div><font face="courier new, monospace">  (Trails l) &gt;&gt;= f = let (Trails r) = f l in</font></div><div><font face="courier new, monospace">    ((there l &lt;&gt; there r),(back r &lt;&gt; back l)) </font></div>

<div><br></div></div><div><br></div><div>But it doesn&#39;t like that either. What am I missing?</div><div><br></div><div>Adrian.</div><div><br></div><div><br></div><div><br></div>
<div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br>
<br><div class="gmail_quote"><div><div class="h5">On 31 May 2013 23:42, Brandon Allbery <span dir="ltr">&lt;<a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a>&gt;</span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div class="h5">
<div dir="ltr"><div>On Fri, May 31, 2013 at 11:06 AM, Adrian May <span dir="ltr">&lt;<a href="mailto:adrian.alexander.may@gmail.com" target="_blank">adrian.alexander.may@gmail.com</a>&gt;</span> wrote:<br></div>
<div class="gmail_extra">
<div class="gmail_quote"><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Well I figured out that I should be using the State monad, but it seems not to be behaving like most of the tutorials on the web. Did the syntax change? ....</div>


</blockquote><div><br></div></div><div>mtl-2.x changed all the base monads (State, Reader, Writer, etc.) from standalone to being transformers atop an Identity monad; this cleans up the implementation considerably (since we don&#39;t have almost exactly the same code for both the standalone and transformer versions, but means that all uses of the standalone constructors must be replaced with functions that build the appropriate transformer. (e.g. State becomes state, unless you want to spell it out as StateT Identity.)</div>

<span><font color="#888888">
<div><br></div><div>-- <br></div></font></span></div><span><font color="#888888"><div dir="ltr"><div>brandon s allbery kf8nh                               sine nomine associates</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a>                                  <a href="mailto:ballbery@sinenomine.net" target="_blank">ballbery@sinenomine.net</a></div>


<div>unix, openafs, kerberos, infrastructure, xmonad        <a href="http://sinenomine.net" target="_blank">http://sinenomine.net</a></div></div>
</font></span></div></div>
<br></div></div>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>