Maybe a better way to phrase that question is, "What is the best way to rewrite this so that it doesn't use recursion?"
If you want to use recursion yourself while you are rewriting the code, I guess that's OK... :-) On Mon, Jul 11, 2016 at 4:01 PM, Nick H <[email protected]> wrote: > Here is a puzzle for you: > > For a large enough list, the code below will fill up the call stack and > crash. It makes sense that the Elm compiler can't optimize it with tail > calls, since the recursive function gets called more than once per > iteration. > > What is the best way to rewrite this without using recursion? > > > > type Tree = Leaf Foo | Node Bar Tree Tree >> >> create : List Foo -> Tree >> create faces = >> case faces of >> [] -> >> dummyFoo >> >> foo :: [] -> >> Leaf f >> >> list -> >> let >> box = wrap list >> >> ( left, right ) = partition box list >> in >> Node box (create left) (create right) >> >> wrap : List Foo -> Bar >> >> partition : Bar -> List Foo -> (List Foo, List Foo) >> >> -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
