@@ -5,10 +5,17 @@ import Prelude
55import Control.Comonad (class Comonad )
66import Control.Extend (class Extend )
77import 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 )
911import Data.Functor.Invariant (class Invariant , imapF )
12+ import Data.FunctorWithIndex (class FunctorWithIndex )
1013import 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 )
1219
1320-- | `Lazy a` represents lazily-computed values of type `a`.
1421-- |
@@ -44,14 +51,16 @@ instance euclideanRingLazy :: EuclideanRing a => EuclideanRing (Lazy a) where
4451 div a b = defer \_ -> force a / force b
4552 mod a b = defer \_ -> force a `mod` force b
4653
47- instance fieldLazy :: Field a => Field (Lazy a )
48-
4954instance eqLazy :: Eq a => Eq (Lazy a ) where
5055 eq x y = (force x) == (force y)
5156
57+ derive instance eq1Lazy :: Eq1 Lazy
58+
5259instance ordLazy :: Ord a => Ord (Lazy a ) where
5360 compare x y = compare (force x) (force y)
5461
62+ derive instance ord1Lazy :: Ord1 Lazy
63+
5564instance boundedLazy :: Bounded a => Bounded (Lazy a ) where
5665 top = defer \_ -> top
5766 bottom = defer \_ -> bottom
@@ -75,6 +84,34 @@ instance booleanAlgebraLazy :: BooleanAlgebra a => BooleanAlgebra (Lazy a)
7584instance functorLazy :: Functor Lazy where
7685 map f l = defer \_ -> f (force l)
7786
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+
78115instance invariantLazy :: Invariant Lazy where
79116 imap = imapF
80117
0 commit comments