File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -228,11 +228,13 @@ instance Monad Seq where
228
228
return = singleton
229
229
xs >>= f = foldl' add empty xs
230
230
where add ys x = ys >< f x
231
+ (>>) = (*>)
231
232
232
233
instance Applicative Seq where
233
234
pure = singleton
234
235
fs <*> xs = foldl' add empty fs
235
236
where add ys f = ys >< fmap f xs
237
+ xs *> ys = replicateSeq (length xs) ys
236
238
237
239
instance MonadPlus Seq where
238
240
mzero = empty
@@ -655,6 +657,19 @@ replicateM n x
655
657
| n >= 0 = unwrapMonad (replicateA n (WrapMonad x))
656
658
| otherwise = error " replicateM takes a nonnegative integer argument"
657
659
660
+ -- | @'replicateSeq' n xs@ concatenates @n@ copies of @xs@.
661
+ replicateSeq :: Int -> Seq a -> Seq a
662
+ replicateSeq n xs
663
+ | n < 0 = error " replicateSeq takes a nonnegative integer argument"
664
+ | n == 0 = empty
665
+ | otherwise = go n xs
666
+ where
667
+ -- Invariant: k >= 1
668
+ go 1 xs = xs
669
+ go k xs | even k = kxs
670
+ | otherwise = xs >< kxs
671
+ where kxs = go (k `quot` 2 ) $! (xs >< xs)
672
+
658
673
-- | /O(1)/. Add an element to the left end of a sequence.
659
674
-- Mnemonic: a triangle with the single element at the pointy end.
660
675
(<|) :: a -> Seq a -> Seq a
You can’t perform that action at this time.
0 commit comments