Skip to content

Commit 246053a

Browse files
committed
[fix] further zip-related tweaks
1 parent fb804f6 commit 246053a

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

src/Data/Container/Applicative/Instances.idr

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ namespace ListApplicative
2323
pure = fromList . pure
2424
fs <*> vs = fromList $ toList fs <*> toList vs
2525

26-
public export
27-
listZip' : List' a -> List' b -> List' (a, b)
28-
listZip' l1 l2 = fromList $ listZip (toList l1) (toList l2)
29-
3026
||| Note that usually it is said that List has two applicative structures
3127
||| one defined above, and another one defined by `zipList` (Section 3 of
3228
||| https://www.staff.city.ac.uk/~ross/papers/Constructors.pdf).
@@ -39,9 +35,11 @@ namespace ListApplicative
3935
||| and we cannot lawfully make `List` an applicative functor in such a way.
4036
||| For instance, this is not a valid applicative instance, because unital
4137
||| laws do not hold:
42-
||| Applicative List' where
43-
||| pure = fromList . pure
44-
||| fs <*> vs = fromList $ uncurry ($) <$> listZip (toList fs) (toList vs)
38+
|||
39+
||| Applicative List where
40+
||| pure a = [a]
41+
||| fs <*> xs = uncurry ($) <$> listZip fs xs
42+
4543

4644

4745
namespace BinTreeLeafApplicative

src/Data/Tree.idr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ namespace BinaryTrees
150150

151151
{--
152152
In general no applicative instance for a tree with values only on nodes.
153+
Note that you can define the `pure` and `liftA2`, but they won't satisfy applicative laws.
153154
See https://www.reddit.com/r/haskell/comments/cb1j40/comment/etct1xk/
154155
--}
155156

src/Misc.idr

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,6 @@ public export
2222
strength : Applicative f => a -> f b -> f (a, b)
2323
strength a fb = liftA2 (pure a) fb
2424

25-
||| Prelude.Types already has one implementation of Applicative List
26-
||| This is the other one, which behaves like a zip
27-
namespace ListApplicative
28-
public export
29-
listZip : List a -> List b -> List (a, b)
30-
listZip [] _ = []
31-
listZip (x :: xs) [] = []
32-
listZip (x :: xs) (y :: ys) = (x, y) :: listZip xs ys
33-
34-
public export
35-
[zipInstance] Applicative List where
36-
pure a = [a]
37-
fs <*> xs = uncurry ($) <$> listZip fs xs
38-
3925
||| Analogue of `(::)` for lists.
4026
||| Takes an element and prepends it to some 'vector'
4127
public export
@@ -116,6 +102,11 @@ namespace List
116102
prod : Num a => List a -> a
117103
prod = foldr (*) (fromInteger 1)
118104

105+
public export
106+
listZip : List a -> List b -> List (a, b)
107+
listZip (x :: xs) (y :: ys) = (x, y) :: listZip xs ys
108+
listZip _ _ = []
109+
119110
public export
120111
maxInList : Ord a => List a -> Maybe a
121112
maxInList [] = Nothing
@@ -529,4 +520,16 @@ filter'' p (x :: xs) with (filter' p xs)
529520
{-
530521
Prelude.absurd : Uninhabited t => t -> a
531522
532-
-}
523+
-}
524+
525+
h : {n : Nat} -> Vect n a -> Nat
526+
h xs = n
527+
528+
529+
g : {0 n : Nat} -> Vect n a -> Nat
530+
g [] = 0
531+
g (x :: xs) = 1 + (g xs)
532+
533+
proof2 : (v : Vect n a) -> g v = n
534+
proof2 [] = Refl
535+
proof2 (x :: xs) = cong (1 +) (proof2 xs)

0 commit comments

Comments
 (0)