on master help sign in
Merge pull request #4377 from brainrape/boundedlist-vector-conversion
007ef39Niklas Larsson
libs/contrib/Data/BoundedList.idr+15
@@ -1,6 +1,7 @@
1module Data.BoundedList
1module Data.BoundedList
2
2
3import Data.Fin
3import Data.Fin
4+import Data.Vect
4
5
5%access public export
6%access public export
6%default total
7%default total
@@ -50,6 +51,20 @@ fromList : (xs : List a) -> BoundedList (length xs) a
50fromList [] = []
51fromList [] = []
51fromList (x :: xs) = x :: fromList xs
52fromList (x :: xs) = x :: fromList xs
52
53
54+--------------------------------------------------------------------------------
55+-- Conversions to and from vector
56+--------------------------------------------------------------------------------
57+
58+||| Convert bounded list to vector.
59+toVect : (xs : BoundedList n a) -> Vect (finToNat (length xs)) a
60+toVect [] = []
61+toVect (x :: xs) = x :: toVect xs
62+
63+||| Convert vector to bounded list.
64+fromVect : (xs : Vect n a) -> BoundedList n a
65+fromVect [] = []
66+fromVect (x :: xs) = x :: fromVect xs
67+
53--------------------------------------------------------------------------------
68--------------------------------------------------------------------------------
54-- Building (bigger) bounded lists
69-- Building (bigger) bounded lists
55--------------------------------------------------------------------------------
70--------------------------------------------------------------------------------