add concatMap

This commit is contained in:
rnhmjoj 2016-11-15 22:23:31 +01:00
parent c205db3ff7
commit ee653f3822
No known key found for this signature in database
GPG Key ID: 362BB82B7E496B7C

View File

@ -155,8 +155,10 @@ reverse (y :- ys) = gcastWith proof (reverse ys ⧺ (y :- Nil))
intersperse a Vec a n Vec a (n :+ Pred n)
intersperse _ Nil = Nil
intersperse _ (x :- Nil) = x :- Nil
intersperse s (x :- xs) = gcastWith (double n) (x :- s :- intersperse s xs)
where n = sLength (x :- xs)
intersperse s (x :- xs) = gcastWith proof (x :- s :- intersperse s xs)
where
n = sLength xs
proof = double (SS n)
-- | 'intercalate' @xs xss@ is equivalent to
@ -204,6 +206,12 @@ concat (xs :- xss) = gcastWith proof (xs ⧺ concat xss)
proof = plus_commut n (m %:× n)
-- | Map a function over all the elements of a vector and concatenate
-- the resulting vectos.
concatMap (a Vec b n) Vec a m Vec b (m :× n)
concatMap f = concat map f
-- | Applied to a singleton natural @n@ and a value produces
-- a vector obtained by duplicating the value @n@ times
replicate S n a Vec a n