@@ -1,6 +1,7 @@
1module Prelude.Vect
1module Prelude.Vect
3import Prelude.Fin
3import Prelude.Fin
4+import Prelude.Foldable
4import Prelude.Functor
5import Prelude.Functor
5import Prelude.List
6import Prelude.List
6import Prelude.Nat
7import Prelude.Nat
@@ -62,13 +63,9 @@ drop (fS k) [] impossible
62drop (fS k) (x::xs) = drop k xs
63drop (fS k) (x::xs) = drop k xs
64--------------------------------------------------------------------------------
65--------------------------------------------------------------------------------
65−-- Conversions to and from list
66+-- Conversion from list (toList is provided by Foldable)
66--------------------------------------------------------------------------------
67--------------------------------------------------------------------------------
68−toList : Vect n a -> List a
70−toList (x::xs) = x :: toList xs
72fromList : (l : List a) -> Vect (length l) a
69fromList : (l : List a) -> Vect (length l) a
73fromList [] = []
70fromList [] = []
74fromList (x::xs) = x :: fromList xs
71fromList (x::xs) = x :: fromList xs
@@ -123,13 +120,9 @@ instance Functor (Vect n) where
124--------------------------------------------------------------------------------
121--------------------------------------------------------------------------------
126−total foldl : (a -> b -> a) -> a -> Vect m b -> a
123+instance Foldable (Vect n) where
128−foldl f e (x::xs) = foldl f (f e x) xs
130−total foldr : (a -> b -> b) -> b -> Vect m a -> b
131−foldr f e [] = e
124+ foldr f e [] = e
132−foldr f e (x::xs) = f x (foldr f e xs)
125+ foldr f e (x::xs) = f x (foldr f e xs)
134--------------------------------------------------------------------------------
127--------------------------------------------------------------------------------
135-- Special folds
128-- Special folds
@@ -139,18 +132,6 @@ concat : Vect m (Vect n a) -> Vect (m * n) a
139concat [] = []
132concat [] = []
140concat (v::vs) = v ++ concat vs
133concat (v::vs) = v ++ concat vs
142−total and : Vect m Bool -> Bool
143−and = foldr (&&) True
145−total or : Vect m Bool -> Bool
146−or = foldr (||) False
148−total any : (a -> Bool) -> Vect m a -> Bool
149−any p = Vect.or . map p
151−total all : (a -> Bool) -> Vect m a -> Bool
152−all p = Vect.and . map p
154--------------------------------------------------------------------------------
135--------------------------------------------------------------------------------
155-- Transformations
136-- Transformations
156--------------------------------------------------------------------------------
137--------------------------------------------------------------------------------