add implicit take/drop
This commit is contained in:
parent
f8365ca381
commit
c1351e2dff
@ -280,18 +280,26 @@ product ∷ Num a ⇒ Vec a n → a
|
|||||||
product = foldr (T.*) 0
|
product = foldr (T.*) 0
|
||||||
|
|
||||||
|
|
||||||
-- | 'take' @n@ applied to a 'Vec', returns the first @n@ element
|
-- | 'take' returns the first @n@ element of the vector
|
||||||
-- of the vector
|
take ∷ ∀ a n m. SingI n ⇒ Vec a m → Vec a n
|
||||||
take ∷ Sℕ n → Vec a m → Vec a n
|
take = take' (sing ∷ Sℕ n)
|
||||||
take SZ _ = Nil
|
|
||||||
take (SS n) (x :- xs) = x :- take n xs
|
|
||||||
|
|
||||||
|
|
||||||
-- | 'drop' @n@ applied to a 'Vec', returns every element of
|
-- | Variant of 'take' with an explicit argument.
|
||||||
-- the vector but the first @n@
|
take' ∷ Sℕ n → Vec a m → Vec a n
|
||||||
drop ∷ Sℕ n → Vec a m → Vec a (m :- n)
|
take' SZ _ = Nil
|
||||||
drop SZ x = x
|
take' (SS n) (x :- xs) = x :- take' n xs
|
||||||
drop (SS n) (x :- xs) = drop n xs
|
|
||||||
|
|
||||||
|
-- | 'drop' returns every element of the vector but the first @n@
|
||||||
|
drop ∷ ∀ a n m. SingI n ⇒ Vec a m → Vec a (m :- n)
|
||||||
|
drop = drop' (sing ∷ Sℕ n)
|
||||||
|
|
||||||
|
|
||||||
|
-- | Variant of 'drop' with an explicit argument.
|
||||||
|
drop' ∷ Sℕ n → Vec a m → Vec a (m :- n)
|
||||||
|
drop' SZ x = x
|
||||||
|
drop' (SS n) (x :- xs) = drop' n xs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user