{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE UndecidableInstances #-}
module Data.Algebra.Pointed
( Pointed (..)
, PointedMonoid (..)
) where
#if __GLASGOW_HASKELL__ <= 802
import Data.Semigroup (Semigroup (..))
#endif
class Pointed p where
point :: p
instance Pointed (Maybe a) where
point :: Maybe a
point = Maybe a
forall a. Maybe a
Nothing
newtype PointedMonoid m = PointedMonoid { forall m. PointedMonoid m -> m
runPointedMonoid :: m }
deriving (Int -> PointedMonoid m -> ShowS
[PointedMonoid m] -> ShowS
PointedMonoid m -> String
(Int -> PointedMonoid m -> ShowS)
-> (PointedMonoid m -> String)
-> ([PointedMonoid m] -> ShowS)
-> Show (PointedMonoid m)
forall m. Show m => Int -> PointedMonoid m -> ShowS
forall m. Show m => [PointedMonoid m] -> ShowS
forall m. Show m => PointedMonoid m -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall m. Show m => Int -> PointedMonoid m -> ShowS
showsPrec :: Int -> PointedMonoid m -> ShowS
$cshow :: forall m. Show m => PointedMonoid m -> String
show :: PointedMonoid m -> String
$cshowList :: forall m. Show m => [PointedMonoid m] -> ShowS
showList :: [PointedMonoid m] -> ShowS
Show, PointedMonoid m -> PointedMonoid m -> Bool
(PointedMonoid m -> PointedMonoid m -> Bool)
-> (PointedMonoid m -> PointedMonoid m -> Bool)
-> Eq (PointedMonoid m)
forall m. Eq m => PointedMonoid m -> PointedMonoid m -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall m. Eq m => PointedMonoid m -> PointedMonoid m -> Bool
== :: PointedMonoid m -> PointedMonoid m -> Bool
$c/= :: forall m. Eq m => PointedMonoid m -> PointedMonoid m -> Bool
/= :: PointedMonoid m -> PointedMonoid m -> Bool
Eq, Eq (PointedMonoid m)
Eq (PointedMonoid m)
-> (PointedMonoid m -> PointedMonoid m -> Ordering)
-> (PointedMonoid m -> PointedMonoid m -> Bool)
-> (PointedMonoid m -> PointedMonoid m -> Bool)
-> (PointedMonoid m -> PointedMonoid m -> Bool)
-> (PointedMonoid m -> PointedMonoid m -> Bool)
-> (PointedMonoid m -> PointedMonoid m -> PointedMonoid m)
-> (PointedMonoid m -> PointedMonoid m -> PointedMonoid m)
-> Ord (PointedMonoid m)
PointedMonoid m -> PointedMonoid m -> Bool
PointedMonoid m -> PointedMonoid m -> Ordering
PointedMonoid m -> PointedMonoid m -> PointedMonoid m
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {m}. Ord m => Eq (PointedMonoid m)
forall m. Ord m => PointedMonoid m -> PointedMonoid m -> Bool
forall m. Ord m => PointedMonoid m -> PointedMonoid m -> Ordering
forall m.
Ord m =>
PointedMonoid m -> PointedMonoid m -> PointedMonoid m
$ccompare :: forall m. Ord m => PointedMonoid m -> PointedMonoid m -> Ordering
compare :: PointedMonoid m -> PointedMonoid m -> Ordering
$c< :: forall m. Ord m => PointedMonoid m -> PointedMonoid m -> Bool
< :: PointedMonoid m -> PointedMonoid m -> Bool
$c<= :: forall m. Ord m => PointedMonoid m -> PointedMonoid m -> Bool
<= :: PointedMonoid m -> PointedMonoid m -> Bool
$c> :: forall m. Ord m => PointedMonoid m -> PointedMonoid m -> Bool
> :: PointedMonoid m -> PointedMonoid m -> Bool
$c>= :: forall m. Ord m => PointedMonoid m -> PointedMonoid m -> Bool
>= :: PointedMonoid m -> PointedMonoid m -> Bool
$cmax :: forall m.
Ord m =>
PointedMonoid m -> PointedMonoid m -> PointedMonoid m
max :: PointedMonoid m -> PointedMonoid m -> PointedMonoid m
$cmin :: forall m.
Ord m =>
PointedMonoid m -> PointedMonoid m -> PointedMonoid m
min :: PointedMonoid m -> PointedMonoid m -> PointedMonoid m
Ord, (forall a b. (a -> b) -> PointedMonoid a -> PointedMonoid b)
-> (forall a b. a -> PointedMonoid b -> PointedMonoid a)
-> Functor PointedMonoid
forall a b. a -> PointedMonoid b -> PointedMonoid a
forall a b. (a -> b) -> PointedMonoid a -> PointedMonoid b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> PointedMonoid a -> PointedMonoid b
fmap :: forall a b. (a -> b) -> PointedMonoid a -> PointedMonoid b
$c<$ :: forall a b. a -> PointedMonoid b -> PointedMonoid a
<$ :: forall a b. a -> PointedMonoid b -> PointedMonoid a
Functor)
instance Semigroup m => Semigroup (PointedMonoid m) where
(PointedMonoid m
m) <> :: PointedMonoid m -> PointedMonoid m -> PointedMonoid m
<> (PointedMonoid m
n) = m -> PointedMonoid m
forall m. m -> PointedMonoid m
PointedMonoid (m
m m -> m -> m
forall a. Semigroup a => a -> a -> a
<> m
n)
instance Monoid m => Monoid (PointedMonoid m) where
mempty :: PointedMonoid m
mempty = m -> PointedMonoid m
forall m. m -> PointedMonoid m
PointedMonoid m
forall a. Monoid a => a
mempty
#if __GLASGOW_HASKELL__ <= 802
mappend (PointedMonoid m) (PointedMonoid n) = PointedMonoid $ mappend m n
#endif
instance Monoid m => Pointed (PointedMonoid m) where
point :: PointedMonoid m
point = PointedMonoid m
forall a. Monoid a => a
mempty