@@ -113,7 +113,7 @@ import Prelude
113113import Control.Alt ((<|>))
114114import Control.Alternative (class Alternative )
115115import Control.Lazy (class Lazy , defer )
116- import Control.Monad.Rec.Class (class MonadRec , Step (..), tailRecM2 )
116+ import Control.Monad.Rec.Class (class MonadRec , Step (..), tailRecM2 , tailRec )
117117import Control.Monad.ST (pureST )
118118import Data.Array.ST (unsafeFreeze , emptySTArray , pushSTArray )
119119import Data.Array.ST.Iterator (iterator , iterate , pushWhile )
@@ -163,15 +163,15 @@ infix 8 range as ..
163163-- |
164164-- | The `Lazy` constraint is used to generate the result lazily, to ensure
165165-- | termination.
166- some :: forall f a . ( Alternative f , Lazy (f (Array a ) )) => f a -> f (Array a )
166+ some :: forall f a . Alternative f => Lazy (f (Array a )) => f a -> f (Array a )
167167some v = (:) <$> v <*> defer (\_ -> many v)
168168
169169-- | Attempt a computation multiple times, returning as many successful results
170170-- | as possible (possibly zero).
171171-- |
172172-- | The `Lazy` constraint is used to generate the result lazily, to ensure
173173-- | termination.
174- many :: forall f a . ( Alternative f , Lazy (f (Array a ) )) => f a -> f (Array a )
174+ many :: forall f a . Alternative f => Lazy (f (Array a )) => f a -> f (Array a )
175175many v = some v <|> pure []
176176
177177-- ------------------------------------------------------------------------------
@@ -521,13 +521,13 @@ span p arr =
521521 { init: arr, rest: [] }
522522 where
523523 breakIndex = go 0
524- go i =
524+ go = tailRec \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 go (i+ 1 ) else Just i
530- Nothing -> Nothing
529+ Just x -> if p x then Loop (i + 1 ) else Done ( Just i)
530+ Nothing -> Done Nothing
531531
532532-- | Group equal, consecutive elements of an array into arrays.
533533-- |
0 commit comments