Skip to content

Commit 6c0f8df

Browse files
committed
Merge pull request #4 from joneshf/master
Add Comonad, Extract, Monoid, Semigroup, and Semigroupoid instances.
2 parents ed7ca30 + cb05570 commit 6c0f8df

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,30 @@
1616

1717
instance bindTuple :: (Semigroup a) => Bind (Tuple a)
1818

19+
instance comonadTuple :: Comonad (Tuple a)
20+
1921
instance eqTuple :: (Eq a, Eq b) => Eq (Tuple a b)
2022

23+
instance extendTuple :: Extend (Tuple a)
24+
2125
instance functorTuple :: Functor (Tuple a)
2226

27+
instance lazyLazy1Tuple :: (Lazy1 l1, Lazy1 l2) => Lazy (Tuple (l1 a) (l2 b))
28+
29+
instance lazyLazy2Tuple :: (Lazy2 l1, Lazy2 l2) => Lazy (Tuple (l1 a b) (l2 c d))
30+
31+
instance lazyTuple :: (Lazy a, Lazy b) => Lazy (Tuple a b)
32+
2333
instance monadTuple :: (Monoid a) => Monad (Tuple a)
2434

35+
instance monoidTuple :: (Monoid a, Monoid b) => Monoid (Tuple a b)
36+
2537
instance ordTuple :: (Ord a, Ord b) => Ord (Tuple a b)
2638

39+
instance semigroupTuple :: (Semigroup a, Semigroup b) => Semigroup (Tuple a b)
40+
41+
instance semigroupoidTuple :: Semigroupoid Tuple
42+
2743
instance showTuple :: (Show a, Show b) => Show (Tuple a b)
2844

2945

src/Data/Tuple.purs

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

3+
import Control.Comonad
4+
import Control.Extend
5+
import Control.Lazy
6+
37
import Data.Array
48
import Data.Monoid
5-
import Control.Lazy
69

710
data Tuple a b = Tuple a b
811

@@ -18,6 +21,15 @@ instance ordTuple :: (Ord a, Ord b) => Ord (Tuple a b) where
1821
EQ -> compare b1 b2
1922
other -> other
2023

24+
instance semigroupoidTuple :: Semigroupoid Tuple where
25+
(<<<) (Tuple _ c) (Tuple a _) = Tuple a c
26+
27+
instance semigroupTuple :: (Semigroup a, Semigroup b) => Semigroup (Tuple a b) where
28+
(<>) (Tuple a1 b1) (Tuple a2 b2) = Tuple (a1 <> a2) (b1 <> b2)
29+
30+
instance monoidTuple :: (Monoid a, Monoid b) => Monoid (Tuple a b) where
31+
mempty = Tuple mempty mempty
32+
2133
instance functorTuple :: Functor (Tuple a) where
2234
(<$>) f (Tuple x y) = Tuple x (f y)
2335

@@ -33,6 +45,12 @@ instance bindTuple :: (Semigroup a) => Bind (Tuple a) where
3345

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

48+
instance extendTuple :: Extend (Tuple a) where
49+
(<<=) f t@(Tuple a b) = Tuple a (f t)
50+
51+
instance comonadTuple :: Comonad (Tuple a) where
52+
extract = snd
53+
3654
instance lazyTuple :: (Lazy a, Lazy b) => Lazy (Tuple a b) where
3755
defer f = Tuple (defer $ \_ -> fst (f unit)) (defer $ \_ -> snd (f unit))
3856

0 commit comments

Comments
 (0)