|
14 | 14 | module Data.List.Fresh where |
15 | 15 |
|
16 | 16 | open import Level using (Level; _⊔_) |
17 | | -open import Data.Bool.Base using (true; false) |
| 17 | +open import Data.Bool.Base using (true; false; if_then_else_) |
18 | 18 | open import Data.Unit.Polymorphic.Base using (⊤) |
19 | 19 | open import Data.Product.Base using (∃; _×_; _,_; -,_; proj₁; proj₂) |
20 | 20 | open import Data.List.Relation.Unary.All using (All; []; _∷_) |
@@ -161,29 +161,28 @@ module _ {P : Pred A p} (P? : U.Decidable P) where |
161 | 161 | takeWhile-# : ∀ {R : Rel A r} a (as : List# A R) → a # as → a # takeWhile as |
162 | 162 |
|
163 | 163 | takeWhile [] = [] |
164 | | - takeWhile (cons a as ps) with does (P? a) |
165 | | - ... | true = cons a (takeWhile as) (takeWhile-# a as ps) |
166 | | - ... | false = [] |
| 164 | + takeWhile (cons a as ps) = |
| 165 | + if does (P? a) then cons a (takeWhile as) (takeWhile-# a as ps) else [] |
167 | 166 |
|
| 167 | + -- this 'with' is needed to cause reduction in the type of 'takeWhile (a ∷# as)' |
168 | 168 | takeWhile-# a [] _ = _ |
169 | 169 | takeWhile-# a (x ∷# xs) (p , ps) with does (P? x) |
170 | 170 | ... | true = p , takeWhile-# a xs ps |
171 | 171 | ... | false = _ |
172 | 172 |
|
173 | 173 | dropWhile : {R : Rel A r} → List# A R → List# A R |
174 | 174 | dropWhile [] = [] |
175 | | - dropWhile aas@(a ∷# as) with does (P? a) |
176 | | - ... | true = dropWhile as |
177 | | - ... | false = aas |
| 175 | + dropWhile aas@(a ∷# as) = if does (P? a) then dropWhile as else aas |
178 | 176 |
|
179 | 177 | filter : {R : Rel A r} → List# A R → List# A R |
180 | 178 | filter-# : ∀ {R : Rel A r} a (as : List# A R) → a # as → a # filter as |
181 | 179 |
|
182 | 180 | filter [] = [] |
183 | | - filter (cons a as ps) with does (P? a) |
184 | | - ... | true = cons a (filter as) (filter-# a as ps) |
185 | | - ... | false = filter as |
| 181 | + filter (cons a as ps) = |
| 182 | + let l = filter as in |
| 183 | + if does (P? a) then cons a l (filter-# a as ps) else l |
186 | 184 |
|
| 185 | + -- this 'with' is needed to cause reduction in the type of 'filter-# a (x ∷# xs)' |
187 | 186 | filter-# a [] _ = _ |
188 | 187 | filter-# a (x ∷# xs) (p , ps) with does (P? x) |
189 | 188 | ... | true = p , filter-# a xs ps |
|
0 commit comments