<div>I doubt this is a problem with the compiler as you state; </div>
<div>It's not immediately obvious by looking at your code what the problem is; the code is really dense and it's not immediately obvious what you are trying to accomplish. I suspect that either you have a bug, or you are pattern-matching against something you are depending on, which will force it to evaluate to weak-head normal form so that it can be matched against.
<div>Take a look at the section titled "Lazy Patterns" for an example of how to solve that problem: <a href="http://www.cs.auckland.ac.nz/references/haskell/haskell-intro-html/patterns.html">http://www.cs.auckland.ac.nz/references/haskell/haskell-intro-html/patterns.html
<div>I don't understand what you are saying about "promises pushed onto the stack". A boxed value can either be a thunk (unevaluated promise) or the evaluated result of that thunk. Calls to functions just push pointers to the boxes onto the stack. When the result is needed the thunk gets evaluated; if it somehow ends up depending on itself the thunk will get called recursively which will eventually end up in a stack overflow.
<div> -- ryan</div>
<div><span class="gmail_quote">On 6/11/07, <b class="gmail_sendername">Michael Speer</b> <<a href="mailto:email@example.com">firstname.lastname@example.org</a>> wrote:</span></div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">The code I reference is located at :<br><br><a href="http://michaelspeer.blogspot.com/2007/06/impossible-is-only-possible-sometimes.html">
http://michaelspeer.blogspot.com/2007/06/impossible-is-only-possible-sometimes.html</a><br><br>In the code I am building a parser for regular expressions. I know it<br>is possible with ghc to have a function that accepts its own output as
<br>its input so long as it does not utilize that piece of output in<br>generating itself.<br><br>E.g.<br>test x y = ( "World" , x , x ++ " " ++ y )<br>main = let ( a , b , c ) = test "Hello" a
<br> in do<br> print $ ( a , b , c )<br><br>-- emits ("World","Hello","Hello World")<br><br>This contrived example works properly. A more complex example can be<br>found in the linked-to function `aexn' ( and-extracted-nodes ).
<br><br>It seems though, if you try this same trick with two different<br>functions that rely on each others input and output, that the compiler<br>will generate code, but the generated program causes the stack to<br>overflow as each function tries to force the other one to evaluate
<br>first and neither bows out releasing an output of promises so that the<br>two functions can resolve. They seem to encounter a lack of laziness.<br>Well, more a duplication of effort. I specifically refer to the<br>linked function `oexn' ( or-extracted-function-nodes ) that performs
<br>this feat. Or would if the program worked after being compiled.<br><br>If the compiler were forced to only make the function call once and<br>mark all variables generated by it immediately with either proper<br>values or promises than the second functions call would receive the
<br>promises in place of the empty variables it feels the need to call the<br>original function to fill.<br><br>Are the promises added to the stack before or after the call? If<br>after, then putting them on before may resolve this. It would likely
<br>make the implementation slower to do so however.<br><br>Is this a known problem that will one day be resolved, or is it<br>considered beyond the scope of the language?<br><br>As I only use ghc, I am unfamiliar if one of the other implementations
<br>could handle this. I have seen nothing referring to it though out my<br>searches regarding the matter.<br><br>- michael speer<br>_______________________________________________<br>Haskell mailing list<br><a href="mailto:Haskell@haskell.org">