File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -23,11 +23,18 @@ listToVec (x ∷ xs) = x ∷ listToVec xs
2323
2424{-# COMPILE AGDA2HS listToVec transparent #-}
2525
26+ vecToList : Vec a n → List a
27+ vecToList [] = []
28+ vecToList (x ∷ xs) = x ∷ vecToList xs
29+
30+ {-# COMPILE AGDA2HS vecToList transparent #-}
31+
2632test2 : Vec Int 3
27- test2 = listToVec (map (_+ 1 ) (1 ∷ 2 ∷ 3 ∷ []))
33+ test2 = listToVec (map (_+ 1 ) (vecToList ( 1 ∷ 2 ∷ 3 ∷ []) ))
2834
2935{-# COMPILE AGDA2HS test2 #-}
3036
37+ -- Not using `length` since compile-to is not yet compatible with type classes
3138llength : List a → Nat
3239llength [] = 0
3340llength (x ∷ xs) = 1 + llength xs
@@ -46,3 +53,20 @@ test3 : ∃ Nat (_≡ 3)
4653test3 = vlength test1
4754
4855{-# COMPILE AGDA2HS test3 #-}
56+
57+ lfoldl : (b → a → b) → b → List a → b
58+ lfoldl f v [] = v
59+ lfoldl f v (x ∷ xs) = lfoldl f (f v x) xs
60+
61+ {-# COMPILE AGDA2HS lfoldl #-}
62+
63+ vfoldl : (b : @0 Nat → Set ) → (∀ {@0 n} → b n → a → b (suc n)) → b 0 → Vec a n → b n
64+ vfoldl b f v [] = v
65+ vfoldl b f v (x ∷ xs) = vfoldl (λ n → b (suc n)) f (f v x) xs
66+
67+ {-# COMPILE AGDA2HS vfoldl to lfoldl #-}
68+
69+ vreverse : Vec a n → Vec a n
70+ vreverse {a = a} = vfoldl (Vec a) (λ xs x → x ∷ xs) []
71+
72+ {-# COMPILE AGDA2HS vreverse #-}
Original file line number Diff line number Diff line change @@ -15,3 +15,10 @@ llength (x : xs) = 1 + llength xs
1515test3 :: Natural
1616test3 = llength test1
1717
18+ lfoldl :: (b -> a -> b ) -> b -> [a ] -> b
19+ lfoldl f v [] = v
20+ lfoldl f v (x : xs) = lfoldl f (f v x) xs
21+
22+ vreverse :: [a ] -> [a ]
23+ vreverse = lfoldl (\ xs x -> x : xs) []
24+
You can’t perform that action at this time.
0 commit comments