Re: [elm-discuss] recursively generating a tree

2016-07-12 Thread Ian Mackenzie
Looks cool! I've sent you some questions and comments in a separate e-mail. On Wednesday, 13 July 2016 09:39:56 UTC+10, Nick H wrote: > > It is! http://package.elm-lang.org/packages/nphollon/collision/1.0.2/ > > I was going to solicit feedback here on elm-discuss once I got this bug > sorted out.

Re: [elm-discuss] recursively generating a tree

2016-07-12 Thread Nick H
It is! http://package.elm-lang.org/packages/nphollon/collision/1.0.2/ I was going to solicit feedback here on elm-discuss once I got this bug sorted out. Until then, I've purposely kept the API to a bare minimum. Would love to hear your thoughts! On Tue, Jul 12, 2016 at 4:14 PM, Ian Mackenzie wr

Re: [elm-discuss] recursively generating a tree

2016-07-12 Thread Ian Mackenzie
Good to know! By the way, is the original code you were working on part of an open-source library, by any chance? I'm working on some 2D/3D geometric libraries for Elm myself, including stuff like bounding boxes and spatial trees much like the one you describe. Might would be worth seeing if th

Re: [elm-discuss] recursively generating a tree

2016-07-12 Thread Nick H
Well, it turns out the bug isn't in my code. It is in elm-lang/core . List.take fills ups the call stack all on its own: main = [ 1 .. 5000 ] |> List.take 2500 |> toString |> Html.text List.drop does not have this problem. If we redefine the partition

Re: [elm-discuss] recursively generating a tree

2016-07-12 Thread Nick H
So I felt this 0.16 tutorial helped me understand trampolines better. Then it took a bit of work rewriting `create` in a way that utilized tail calls. But the new version is still failing with "too much re

Re: [elm-discuss] recursively generating a tree

2016-07-12 Thread Max Goldstein
Nah, trampoline takes some mental gymnastics! Hope it's helpful for your tree problem. -- 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...@g

Re: [elm-discuss] recursively generating a tree

2016-07-12 Thread Nick H
*sigh* Never mind, I am being dumb. factorial : Int -> Int factorial x = Trampoline.evaluate (fac 1 x) fac : Int -> Int -> Trampoline Int fac acc n = if n <= 0 then Trampoline.done acc else Trampoline.jump (\_ -> fac (n * acc) (n - 1)) On Tue, Jul 12, 2016 at 9:17 A

Re: [elm-discuss] recursively generating a tree

2016-07-12 Thread Nick H
... and I have no idea how this is supposed to work. Even for primitive recursion factorial : Int -> Int factorial x = Trampoline.evaluate (fac x) fac : Int -> Trampoline Int fac x = if x <= 0 then Trampoline.done 1 else Trampoline.jump (\_ ->

Re: [elm-discuss] recursively generating a tree

2016-07-12 Thread Nick H
Ian, that is a great thought, but even if we split the list exactly in half, the call stack fills up when the list length gets to around 4500. partition _ list = let n = List.length list // 2 in (List.take n list, List.drop n list) In my specific problem, the "wrap" function finds the

Re: [elm-discuss] recursively generating a tree

2016-07-12 Thread Janis Voigtländer
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 th

[elm-discuss] recursively generating a tree

2016-07-11 Thread 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 usin