<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>Well, the simplest solution I can think of is below. &nbsp;The OtherNormalStateT doesn't actually have any state at all, but still gets state from the StateT 'below' it and returns a result.</div><div><br></div><div>This is still a bit ugly, but it compiles - and although I haven't tested it properly yet, simply implementing the 'other' helper function to do the work should be fine.</div><div><br></div><div>It's a question of how smart the compiler is. &nbsp;Obviously this is inefficient in theory, but will the compiler notice we are passing around a 'unit' state and that the s -> (a,s) function doesn't care about the input.... perhaps. &nbsp;I'd expect the overhead from this to be fairly small and it does allow me to continue using the same paradigm for stateless versions of my normal generator.</div><div><br></div><div>I have seen people do similar things when they wish to carry around state but have no result, and thus the result is set to (). &nbsp;I can't see why this is any less inefficient than that?</div><div><br></div><div><br></div><div><br></div><div>type BoxMullerStateT = StateT (Maybe Double)</div><div>type BoxMullerRandomStateStack = BoxMullerStateT MyRngState</div><div><br></div><div><div>instance NormalClass BoxMullerRandomStateStack where</div><div>&nbsp;&nbsp;generateNormal = StateT $ \s -> case s of</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>&nbsp;&nbsp;<span class="Apple-tab-span" style="white-space: pre; ">                        </span>Just d &nbsp;-> return (d,Nothing)</div><div><span class="Apple-tab-span" style="white-space: pre; ">                </span>&nbsp;&nbsp;<span class="Apple-tab-span" style="white-space: pre; ">                </span>Nothing -> do qrnBaseList &lt;- nextRand</div><div><span class="Apple-tab-span" style="white-space: pre; ">                                        </span>&nbsp;&nbsp; &nbsp; &nbsp;let (norm1,norm2) = boxMuller (head qrnBaseList) (head $ tail qrnBaseList)</div><div><span class="Apple-tab-span" style="white-space: pre; ">                                        </span>&nbsp;&nbsp; &nbsp; &nbsp;return (norm1,Just norm2)</div><div><br></div><div><br></div></div><div>-- New stateless StateT below!</div><div><br></div><div>type OtherNormalStateT = StateT ()</div><div>type OtherRandomStateStack = OtherNormalStateT MyRngState</div><div><br></div><div><br></div><div><br></div><div>instance NormalClass OtherRandomStateStack where</div><div>&nbsp;&nbsp; &nbsp;generateNormal = StateT $ \_ -> do rn:rns &lt;- nextRand&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return ( other rn, () )</div></div><div><br></div><br><div><div>On 17 Jun 2009, at 07:38, Jason Dagit wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi Phil,<br><br><div class="gmail_quote">On Mon, Jun 15, 2009 at 5:23 PM, Phil <span dir="ltr">&lt;<a href="mailto:phil@beadling.co.uk">phil@beadling.co.uk</a>></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;"> Hi,<br><br>I'm trying to think around a problem which is causing me some difficulty in Haskell.<br><br>I'm representing a stateful computation using a State Transform - which works fine.&nbsp; Problem is in order to add flexibility to my program I want to performs the&nbsp;</blockquote></div></blockquote><div><br></div><div><br></div><div>&lt;snip></div><div><br></div><blockquote type="cite"><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><span class="Apple-style-span" style="-webkit-text-stroke-width: -1; ">g my own Monad from scratch but this crossed my mind as another possibillity - i.e. a Monad that either has a state of maybe double, or has no state at all?</span></blockquote><div><br>I have a feeling I'd just 'return' the pure computations into the state monad.&nbsp; My example code above seems weird and heavy weight to me.<br> <br>I'd love to see what you figure you.<br><br>Jason<br></div></div><br> _______________________________________________<br>Haskell-Cafe mailing list<br><a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>http://www.haskell.org/mailman/listinfo/haskell-cafe<br></blockquote></div><br></body></html>