11{-# LANGUAGE CPP, DeriveDataTypeable, DeriveTraversable, DeriveFoldable,
22 DeriveGeneric #-}
3- module Data.Functor.Of where
3+ module Data.Functor.Of ( Of ( .. )) where
44import Data.Monoid (Monoid (.. ))
55import Data.Semigroup (Semigroup (.. ))
66import Control.Applicative
77import Data.Traversable (Traversable )
88import Data.Foldable (Foldable )
9- #if MIN_VERSION_base(4,8,0)
109import Data.Bifunctor
11- #endif
1210import Data.Data
13- import Data.Typeable
14- import GHC.Generics (Generic , Generic1 )
11+ #if MIN_VERSION_base(4,9,0)
1512import Data.Functor.Classes
13+ import Data.Foldable (Foldable )
14+ import Data.Traversable (Traversable )
15+ #endif
16+ import GHC.Generics (Generic , Generic1 )
1617
1718-- | A left-strict pair; the base functor for streams of individual elements.
1819data Of a b = !a :> b
@@ -35,7 +36,7 @@ instance (Monoid a, Monoid b) => Monoid (Of a b) where
3536instance Functor (Of a ) where
3637 fmap f (a :> x) = a :> f x
3738 {-#INLINE fmap #-}
38- a <$ (b :> x ) = b :> a
39+ a <$ (b :> _ ) = b :> a
3940 {-#INLINE (<$) #-}
4041
4142#if MIN_VERSION_base(4,8,0)
@@ -51,40 +52,43 @@ instance Bifunctor Of where
5152instance Monoid a => Applicative (Of a ) where
5253 pure x = mempty :> x
5354 {-#INLINE pure #-}
54- m :> f <*> m' :> x = mappend m m' :> f x
55+ ( m :> f) <*> ( m' :> x) = mappend m m' :> f x
5556 {-#INLINE (<*>) #-}
56- m :> x *> m' :> y = mappend m m' :> y
57+ ( m :> _) *> ( m' :> y) = mappend m m' :> y
5758 {-#INLINE (*>) #-}
58- m :> x <* m' :> y = mappend m m' :> x
59+ ( m :> x) <* ( m' :> _) = mappend m m' :> x
5960 {-#INLINE (<*) #-}
6061
6162instance Monoid a => Monad (Of a ) where
62- return x = mempty :> x
63+ return = pure
6364 {-#INLINE return #-}
64- m :> x >> m' :> y = mappend m m' :> y
65+ ( m :> _) >> ( m' :> y) = mappend m m' :> y
6566 {-#INLINE (>>) #-}
66- m :> x >>= f = let m' :> y = f x in mappend m m' :> y
67+ ( m :> x) >>= f = let m' :> y = f x in mappend m m' :> y
6768 {-#INLINE (>>=) #-}
6869
70+ #if MIN_VERSION_base(4,9,0)
6971instance Show a => Show1 (Of a ) where
7072 liftShowsPrec = liftShowsPrec2 showsPrec showList
7173
74+ instance Eq a => Eq1 (Of a ) where
75+ liftEq = liftEq2 (==)
76+
77+ instance Ord a => Ord1 (Of a ) where
78+ liftCompare = liftCompare2 compare
79+
7280instance Show2 Of where
7381 liftShowsPrec2 spa _sla spb _slb p (a :> b) =
7482 showParen (p > 5 ) $
7583 spa 6 a .
7684 showString " :> " .
7785 spb 6 b
7886
79- instance Eq a => Eq1 (Of a ) where
80- liftEq = liftEq2 (==)
81-
82- instance Ord a => Ord1 (Of a ) where
83- liftCompare = liftCompare2 compare
84-
8587instance Eq2 Of where
86- liftEq2 eq1 eq2 (x :> y) (z :> w) = eq1 x z && eq2 y w
88+ liftEq2 f g (x :> y) (z :> w) = f x z && g y w
8789
8890instance Ord2 Of where
8991 liftCompare2 comp1 comp2 (x :> y) (z :> w) =
9092 comp1 x z `mappend` comp2 y w
93+ #endif
94+
0 commit comments