Skip to content

Add Lazy instances #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"package.json"
],
"dependencies": {
"purescript-arrays": "*",
"purescript-monoid": "*"
"purescript-arrays": "~0.2.0",
"purescript-monoid": "*",
"purescript-control": "~0.2.0"
}
}
12 changes: 11 additions & 1 deletion src/Data/Tuple.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Data.Tuple where

import Data.Array
import Data.Monoid
import Control.Lazy

data Tuple a b = Tuple a b

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

instance bindTuple :: (Semigroup a) => Bind (Tuple a) where
(>>=) (Tuple a1 b) f = case f b of
(>>=) (Tuple a1 b) f = case f b of
Tuple a2 c -> Tuple (a1 <> a2) c

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

instance lazyTuple :: (Lazy a, Lazy b) => Lazy (Tuple a b) where
defer f = Tuple (defer $ \_ -> fst (f unit)) (defer $ \_ -> snd (f unit))

instance lazyLazy1Tuple :: (Lazy1 l1, Lazy1 l2) => Lazy (Tuple (l1 a) (l2 b)) where
defer f = Tuple (defer1 $ \_ -> fst (f unit)) (defer1 $ \_ -> snd (f unit))

instance lazyLazy2Tuple :: (Lazy2 l1, Lazy2 l2) => Lazy (Tuple (l1 a b) (l2 c d)) where
defer f = Tuple (defer2 $ \_ -> fst (f unit)) (defer2 $ \_ -> snd (f unit))

fst :: forall a b. Tuple a b -> a
fst (Tuple a _) = a

Expand Down