on master help sign in
Merge pull request #4377 from brainrape/boundedlist-vector-conversion

Add conversions between BoundedList and Vect

commit007ef39405f03c42fd99f1d955c12af592552565 authorNiklas Larsson <metaniklas@gmail.com> dateFri 16 Mar 2018, 23:32 (9 years ago) parentc74a6463456b43
1 file changed+15
libs/contrib/Data/BoundedList.idr+15
libs/contrib/Data/BoundedList.idr+15
@@ -1,6 +1,7 @@
11module Data.BoundedList
22
33import Data.Fin
4+import Data.Vect
45
56%access public export
67%default total
@@ -50,6 +51,20 @@ fromList : (xs : List a) -> BoundedList (length xs) a
5051fromList [] = []
5152fromList (x :: xs) = x :: fromList xs
5253
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+
5368--------------------------------------------------------------------------------
5469-- Building (bigger) bounded lists
5570--------------------------------------------------------------------------------