Skip to content

Commit ed7ca30

Browse files
committed
Merge pull request #3 from purescript/lazy
Add Lazy instances
2 parents 4cab01c + 7397fc1 commit ed7ca30

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

bower.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"package.json"
1919
],
2020
"dependencies": {
21-
"purescript-arrays": "*",
22-
"purescript-monoid": "*"
21+
"purescript-arrays": "~0.2.0",
22+
"purescript-monoid": "*",
23+
"purescript-control": "~0.2.0"
2324
}
2425
}

src/Data/Tuple.purs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Data.Tuple where
22

33
import Data.Array
44
import Data.Monoid
5+
import Control.Lazy
56

67
data Tuple a b = Tuple a b
78

@@ -27,11 +28,20 @@ instance applicativeTuple :: (Monoid a) => Applicative (Tuple a) where
2728
pure = Tuple mempty
2829

2930
instance bindTuple :: (Semigroup a) => Bind (Tuple a) where
30-
(>>=) (Tuple a1 b) f = case f b of
31+
(>>=) (Tuple a1 b) f = case f b of
3132
Tuple a2 c -> Tuple (a1 <> a2) c
3233

3334
instance monadTuple :: (Monoid a) => Monad (Tuple a)
3435

36+
instance lazyTuple :: (Lazy a, Lazy b) => Lazy (Tuple a b) where
37+
defer f = Tuple (defer $ \_ -> fst (f unit)) (defer $ \_ -> snd (f unit))
38+
39+
instance lazyLazy1Tuple :: (Lazy1 l1, Lazy1 l2) => Lazy (Tuple (l1 a) (l2 b)) where
40+
defer f = Tuple (defer1 $ \_ -> fst (f unit)) (defer1 $ \_ -> snd (f unit))
41+
42+
instance lazyLazy2Tuple :: (Lazy2 l1, Lazy2 l2) => Lazy (Tuple (l1 a b) (l2 c d)) where
43+
defer f = Tuple (defer2 $ \_ -> fst (f unit)) (defer2 $ \_ -> snd (f unit))
44+
3545
fst :: forall a b. Tuple a b -> a
3646
fst (Tuple a _) = a
3747

0 commit comments

Comments
 (0)