3 | module Data.Seq.Unsized
5 | import Control.WellFounded
6 | import public Data.Zippable
8 | import Data.Seq.Internal
14 | data Seq : Type -> Type where
15 | MkSeq : FingerTree (Elem e)
29 | MkSeq (Single (MkElem a))
33 | replicate : (n : Nat)
37 | MkSeq (replicate' n a)
50 | reverse (MkSeq tr) =
51 | MkSeq (reverseTree id tr)
53 | export infixr 5 `cons`
60 | MkSeq (MkElem a `consTree` tr)
62 | export infixl 5 `snoc`
69 | MkSeq (tr `snocTree` MkElem a)
76 | MkSeq t1 ++ MkSeq t2 =
77 | MkSeq (addTree0 t1 t2)
84 | case viewLTree tr of
85 | Just (MkElem a, tr') =>
112 | -> Maybe (Seq a, a)
114 | case viewRTree tr of
115 | Just (tr', MkElem a) =>
116 | Just (MkSeq tr', a)
144 | MkSeq (foldr (\x, t => MkElem x `consTree` t) Empty xs)
151 | index i (MkSeq t) =
154 | let (_, MkElem a) = lookupTree i t
166 | adjust f i s@(MkSeq t) =
169 | MkSeq $
adjustTree (const (map f)) i t
181 | adjust (const a) i t
189 | splitAt i s@(MkSeq t) =
192 | let (l, r) = split i t
193 | in (MkSeq l, MkSeq r)
204 | fst (splitAt i seq)
213 | snd (splitAt i seq)
224 | implementation Eq a => Eq (Seq a) where
225 | MkSeq x == MkSeq y = x == y
228 | implementation Ord a => Ord (Seq a) where
229 | compare (MkSeq x) (MkSeq y) = compare x y
232 | implementation Functor Seq where
233 | map f (MkSeq tr) = MkSeq (map (map f) tr)
236 | implementation Foldable Seq where
237 | foldr f z (MkSeq tr) = foldr (f . unElem) z tr
238 | foldl f z (MkSeq tr) = foldl (\acc, (MkElem elem) => f acc elem) z tr
239 | toList (MkSeq tr) = toList' tr
240 | null (MkSeq Empty) = True
244 | implementation Traversable Seq where
245 | traverse f (MkSeq tr) = MkSeq <$> traverse (map MkElem . f . unElem) tr
248 | implementation Show a => Show (Seq a) where
249 | showPrec p = showPrec p . toList
252 | implementation Zippable Seq where
253 | zipWith f (MkSeq x) (MkSeq y) = MkSeq (zipWith' f x y)
254 | zipWith3 f (MkSeq x) (MkSeq y) (MkSeq z) = MkSeq (zipWith3' f x y z)
255 | unzipWith f (MkSeq zs) = let (xs, ys) = unzipWith' f zs in (MkSeq xs, MkSeq ys)
256 | unzipWith3 f (MkSeq ws) = let (xs, ys, zs) = unzipWith3' f ws in (MkSeq xs, MkSeq ys, MkSeq zs)
259 | implementation Semigroup (Seq a) where
263 | implementation Monoid (Seq a) where
268 | implementation Applicative Seq where
270 | fs <*> xs = foldMap (\f => map f xs) fs
273 | [ListLike] Alternative Seq where
278 | [MaybeLike] Alternative Seq where
280 | MkSeq Empty <|> b = b
284 | implementation Monad Seq where
285 | xs >>= f = foldMap f xs
288 | implementation Sized (Seq a) where
289 | size (MkSeq s) = size s