That's great to hear! Whenever I searched for this, I only found an old 
elm-dev post where implementing it was still being talked about.

I haven't really needed to write recursive loops in Elm yet. But in F#, 
I've written a few.

On Thursday, October 13, 2016 at 11:21:50 PM UTC-5, Joey Eremondi wrote:
>
> One current limitation of Elm is that there is no tail call elimination
>
>
> Like Janis says, this is not true, and in most cases, tail-recursive 
> functions will become while-loops in the resulting JS.
>
> For example, consider a list-summing function:
>
> sum : List Int -> Int
> sum =
>   let
>     helper accum lst =
>       case lst of
>         [] -> accum
>         (h :: t) -> helper (h + accum) t
>   in
>     helper 0
>
> This gets turned into the following JS in 0.18 (though TCO has been around 
> for a few versions):
>
> var _user$project$Main$sum = function () {
>     var helper = F2(
>         function (accum, lst) {
>             helper:
>             while (true) {
>                 var _p0 = lst;
>                 if (_p0.ctor === '[]') {
>                     return accum;
>                 } else {
>                     var _v1 = _p0._0 + accum,
>                         _v2 = _p0._1;
>                     accum = _v1;
>                     lst = _v2;
>                     continue helper;
>                 }
>             }
>         });
>     return helper(0);
> }();
>
>  
>
> On Thu, Oct 13, 2016 at 9:10 PM, Janis Voigtländer <janis.voi...@gmail.com 
> <javascript:>> wrote:
>
>> Your statement about tail call elimination is wrong. The Elm compiler 
>> does it. 
>>
>> Am 13.10.2016 um 23:38 schrieb Kasey Speakman <kjspe...@gmail.com 
>> <javascript:>>:
>>
>> It probably sounds insane that Elm doesn't have `for` or `while`. It 
>> would to me before exposure to functional programming.
>>
>> There are prebuilt functions for working with collections like List 
>> <http://package.elm-lang.org/packages/elm-lang/core/latest/List> and 
>> Array <http://package.elm-lang.org/packages/elm-lang/core/4.0.5/Array> 
>> which will take care of most needs.
>>
>> When you find you need something a bit more custom, a recursive loop is 
>> the normal way. Those take a little practice to get the feel for them.
>>
>> Often when I write my own recursive loop, I later find that I can 
>> accomplish the same by combining list operations or by just playing with 
>> List.foldr.
>>
>> One current limitation of Elm is that there is no tail call elimination 
>> when using a recursive loop, so if you write your own loop and have a large 
>> list, you can get a stack overflow. In practice, this is not a typical 
>> problem due to other factors. I.e. miles of data on the screen impacts 
>> performance, and is not considered good UX.
>>
>> On Wednesday, October 12, 2016 at 5:52:31 AM UTC-5, Patricia Nicole 
>> Benedicto wrote:
>>>
>>> hi can i ask what is the repetiton control structucture of this 
>>> programming languages?
>>>
>> -- 
>> 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 elm-discuss...@googlegroups.com <javascript:>.
>> 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 elm-discuss...@googlegroups.com <javascript:>.
>> 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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to