Skip to content

Commit 9a5770d

Browse files
authored
Merge pull request #100 from purescript/span-tco
Restore compiler-optimized TCO for span
2 parents e3abdd1 + a9dd884 commit 9a5770d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Data/Array.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ import Prelude
113113
import Control.Alt ((<|>))
114114
import Control.Alternative (class Alternative)
115115
import Control.Lazy (class Lazy, defer)
116-
import Control.Monad.Rec.Class (class MonadRec, Step(..), tailRecM2, tailRec)
116+
import Control.Monad.Rec.Class (class MonadRec, Step(..), tailRecM2)
117117
import Control.Monad.ST (pureST)
118118
import Data.Array.ST (unsafeFreeze, emptySTArray, pushSTArray)
119119
import Data.Array.ST.Iterator (iterator, iterate, pushWhile)
@@ -521,13 +521,13 @@ span p arr =
521521
{ init: arr, rest: [] }
522522
where
523523
breakIndex = go 0
524-
go = tailRec \i ->
524+
go i =
525525
-- This looks like a good opportunity to use the Monad Maybe instance,
526526
-- but it's important to write out an explicit case expression here in
527527
-- order to ensure that TCO is triggered.
528528
case index arr i of
529-
Just x -> if p x then Loop (i + 1) else Done (Just i)
530-
Nothing -> Done Nothing
529+
Just x -> if p x then go (i + 1) else Just i
530+
Nothing -> Nothing
531531

532532
-- | Group equal, consecutive elements of an array into arrays.
533533
-- |

0 commit comments

Comments
 (0)