Simplify Trampoline datatype.
This commit is contained in:
parent
84aab5843b
commit
b47166144d
2 changed files with 8 additions and 9 deletions
|
@ -10,11 +10,11 @@ Elm.Native.Trampoline.make = function(elm) {
|
|||
trampoline = function(t) {
|
||||
var tramp = t;
|
||||
while(true) {
|
||||
switch(tramp._0.ctor) {
|
||||
case "Left":
|
||||
return tramp._0._0;
|
||||
case "Right":
|
||||
tramp = tramp._0._0({ctor: "_Tuple0"});
|
||||
switch(tramp.ctor) {
|
||||
case "Done":
|
||||
return tramp._0;
|
||||
case "Continue":
|
||||
tramp = tramp._0({ctor: "_Tuple0"});
|
||||
continue;
|
||||
}
|
||||
_E.Case("Trampoline", "in Native.Trampoline.trampoline");
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
module Trampoline (Trampoline, trampoline)
|
||||
where
|
||||
module Trampoline where
|
||||
|
||||
{-| Trampolining loops for unbounded recursion.
|
||||
Since most javascript implementations lack tail-call elimination, deeply tail-recursive functions will result in a stack overflow.
|
||||
|
@ -33,10 +32,10 @@ main = asText <| fac 1000000000000
|
|||
@docs Trampoline, trampoline
|
||||
-}
|
||||
import Native.Trampoline
|
||||
import open Either
|
||||
|
||||
{-| A computation that might loop. A trampoline is either the resulting value or a thunk that needs to be run more. -}
|
||||
data Trampoline a = Trampoline (Either a (() -> Trampoline a))
|
||||
data Trampoline a = Done a
|
||||
| Continue (() -> Trampoline a)
|
||||
|
||||
{-| Run a trampolining loop in constant space. -}
|
||||
trampoline : Trampoline a -> a
|
||||
|
|
Loading…
Reference in a new issue