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 @@ -233,11 +233,13 @@ instance Monad Seq where
233
233
return = singleton
234
234
xs >>= f = foldl' add empty xs
235
235
where add ys x = ys >< f x
236
+ (>>) = (*>)
236
237
237
238
instance Applicative Seq where
238
239
pure = singleton
239
240
fs <*> xs = foldl' add empty fs
240
241
where add ys f = ys >< fmap f xs
242
+ xs *> ys = replicateSeq (length xs) ys
241
243
242
244
instance MonadPlus Seq where
243
245
mzero = empty
@@ -660,6 +662,19 @@ replicateM n x
660
662
| n >= 0 = unwrapMonad (replicateA n (WrapMonad x))
661
663
| otherwise = error " replicateM takes a nonnegative integer argument"
662
664
665
+ -- | @'replicateSeq' n xs@ concatenates @n@ copies of @xs@.
666
+ replicateSeq :: Int -> Seq a -> Seq a
667
+ replicateSeq n xs
668
+ | n < 0 = error " replicateSeq takes a nonnegative integer argument"
669
+ | n == 0 = empty
670
+ | otherwise = go n xs
671
+ where
672
+ -- Invariant: k >= 1
673
+ go 1 xs = xs
674
+ go k xs | even k = kxs
675
+ | otherwise = xs >< kxs
676
+ where kxs = go (k `quot` 2 ) $! (xs >< xs)
677
+
663
678
-- | /O(1)/. Add an element to the left end of a sequence.
664
679
-- Mnemonic: a triangle with the single element at the pointy end.
665
680
(<|) :: a -> Seq a -> Seq a
You can’t perform that action at this time.
0 commit comments