Maybe the Trampoline library can help you?

http://package.elm-lang.org/packages/elm-lang/trampoline/1.0.0/Trampoline

Am Dienstag, 12. Juli 2016 schrieb Nick H :

> 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]
> <javascript:_e(%7B%7D,'cvml','elm-discuss%[email protected]');>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.

Reply via email to