@@ -5,10 +5,17 @@ import Prelude
5
5
import Control.Comonad (class Comonad )
6
6
import Control.Extend (class Extend )
7
7
import Control.Lazy as CL
8
-
8
+ import Data.Eq (class Eq1 )
9
+ import Data.Foldable (class Foldable , foldMap , foldl , foldr )
10
+ import Data.FoldableWithIndex (class FoldableWithIndex )
9
11
import Data.Functor.Invariant (class Invariant , imapF )
12
+ import Data.FunctorWithIndex (class FunctorWithIndex )
10
13
import Data.HeytingAlgebra (implies , ff , tt )
11
- import Data.Monoid (class Monoid , mempty )
14
+ import Data.Ord (class Ord1 )
15
+ import Data.Semigroup.Foldable (class Foldable1 , fold1Default )
16
+ import Data.Semigroup.Traversable (class Traversable1 )
17
+ import Data.Traversable (class Traversable , traverse )
18
+ import Data.TraversableWithIndex (class TraversableWithIndex )
12
19
13
20
-- | `Lazy a` represents lazily-computed values of type `a`.
14
21
-- |
@@ -44,14 +51,16 @@ instance euclideanRingLazy :: EuclideanRing a => EuclideanRing (Lazy a) where
44
51
div a b = defer \_ -> force a / force b
45
52
mod a b = defer \_ -> force a `mod` force b
46
53
47
- instance fieldLazy :: Field a => Field (Lazy a )
48
-
49
54
instance eqLazy :: Eq a => Eq (Lazy a ) where
50
55
eq x y = (force x) == (force y)
51
56
57
+ derive instance eq1Lazy :: Eq1 Lazy
58
+
52
59
instance ordLazy :: Ord a => Ord (Lazy a ) where
53
60
compare x y = compare (force x) (force y)
54
61
62
+ derive instance ord1Lazy :: Ord1 Lazy
63
+
55
64
instance boundedLazy :: Bounded a => Bounded (Lazy a ) where
56
65
top = defer \_ -> top
57
66
bottom = defer \_ -> bottom
@@ -75,6 +84,34 @@ instance booleanAlgebraLazy :: BooleanAlgebra a => BooleanAlgebra (Lazy a)
75
84
instance functorLazy :: Functor Lazy where
76
85
map f l = defer \_ -> f (force l)
77
86
87
+ instance functorWithIndexLazy :: FunctorWithIndex Unit Lazy where
88
+ mapWithIndex f = map $ f unit
89
+
90
+ instance foldableLazy :: Foldable Lazy where
91
+ foldr f z l = f (force l) z
92
+ foldl f z l = f z (force l)
93
+ foldMap f l = f (force l)
94
+
95
+ instance foldableWithIndexLazy :: FoldableWithIndex Unit Lazy where
96
+ foldrWithIndex f = foldr $ f unit
97
+ foldlWithIndex f = foldl $ f unit
98
+ foldMapWithIndex f = foldMap $ f unit
99
+
100
+ instance foldable1Lazy :: Foldable1 Lazy where
101
+ foldMap1 f l = f (force l)
102
+ fold1 = fold1Default
103
+
104
+ instance traversableLazy :: Traversable Lazy where
105
+ traverse f l = defer <<< const <$> f (force l)
106
+ sequence l = defer <<< const <$> force l
107
+
108
+ instance traversableWithIndexLazy :: TraversableWithIndex Unit Lazy where
109
+ traverseWithIndex f = traverse $ f unit
110
+
111
+ instance traversable1Lazy :: Traversable1 Lazy where
112
+ traverse1 f l = defer <<< const <$> f (force l)
113
+ sequence1 l = defer <<< const <$> force l
114
+
78
115
instance invariantLazy :: Invariant Lazy where
79
116
imap = imapF
80
117
0 commit comments