{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE NoNamedWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Data.Foldable.Singletons (
PFoldable(..), SFoldable(..),
FoldrM, sFoldrM,
FoldlM, sFoldlM,
Traverse_, sTraverse_,
For_, sFor_,
SequenceA_, sSequenceA_,
Asum, sAsum,
MapM_, sMapM_,
ForM_, sForM_,
Sequence_, sSequence_,
Msum, sMsum,
Concat, sConcat,
ConcatMap, sConcatMap,
And, sAnd,
Or, sOr,
Any, sAny,
All, sAll,
MaximumBy, sMaximumBy,
MinimumBy, sMinimumBy,
NotElem, sNotElem,
Find, sFind,
FoldSym0, FoldSym1,
FoldMapSym0, FoldMapSym1, FoldMapSym2,
FoldrSym0, FoldrSym1, FoldrSym2, FoldrSym3,
Foldr'Sym0, Foldr'Sym1, Foldr'Sym2, Foldr'Sym3,
FoldlSym0, FoldlSym1, FoldlSym2, FoldlSym3,
Foldl'Sym0, Foldl'Sym1, Foldl'Sym2, Foldl'Sym3,
Foldr1Sym0, Foldr1Sym1, Foldr1Sym2,
Foldl1Sym0, Foldl1Sym1, Foldl1Sym2,
ToListSym0, ToListSym1,
NullSym0, NullSym1,
LengthSym0, LengthSym1,
ElemSym0, ElemSym1, ElemSym2,
MaximumSym0, MaximumSym1,
MinimumSym0, MinimumSym1,
SumSym0, SumSym1,
ProductSym0, ProductSym1,
FoldrMSym0, FoldrMSym1, FoldrMSym2, FoldrMSym3,
FoldlMSym0, FoldlMSym1, FoldlMSym2, FoldlMSym3,
Traverse_Sym0, Traverse_Sym1, Traverse_Sym2,
For_Sym0, For_Sym1, For_Sym2,
SequenceA_Sym0, SequenceA_Sym1,
AsumSym0, AsumSym1,
MapM_Sym0, MapM_Sym1, MapM_Sym2,
ForM_Sym0, ForM_Sym1, ForM_Sym2,
Sequence_Sym0, Sequence_Sym1,
MsumSym0, MsumSym1,
ConcatSym0, ConcatSym1,
ConcatMapSym0, ConcatMapSym1, ConcatMapSym2,
AndSym0, AndSym1,
OrSym0, OrSym1,
AnySym0, AnySym1, AnySym2,
AllSym0, AllSym1, AllSym2,
MaximumBySym0, MaximumBySym1, MaximumBySym2,
MinimumBySym0, MinimumBySym1, MinimumBySym2,
NotElemSym0, NotElemSym1, NotElemSym2,
FindSym0, FindSym1, FindSym2
) where
import Control.Applicative
import Control.Monad
import Control.Monad.Singletons.Internal
import Data.Bool.Singletons
import Data.Either.Singletons
import Data.Eq.Singletons
import Data.Kind
import Data.List.NonEmpty (NonEmpty(..))
import Data.List.Singletons.Internal.Disambiguation
import Data.Maybe.Singletons
import Data.Monoid hiding (All(..), Any(..), Endo(..), Product(..), Sum(..))
import Data.Monoid.Singletons
hiding ( AllSym0, AllSym1
, AnySym0, AnySym1
, ProductSym0, ProductSym1
, SumSym0, SumSym1 )
import qualified Data.Monoid as Monoid (Product(..), Sum(..))
import Data.Ord.Singletons
hiding ( Max, MaxSym0, MaxSym1, MaxSym2, sMax
, Min, MinSym0, MinSym1, MinSym2, sMin )
import Data.Semigroup.Singletons.Internal.Classes
import Data.Semigroup.Singletons.Internal.Disambiguation
import Data.Singletons
import Data.Singletons.Base.Instances
hiding (Foldl, FoldlSym0(..), FoldlSym1(..), FoldlSym2(..), FoldlSym3, sFoldl)
import Data.Singletons.TH
import GHC.Base.Singletons
hiding (Foldr, FoldrSym0, FoldrSym1, FoldrSym2, FoldrSym3, sFoldr)
import GHC.Num.Singletons
import GHC.TypeLits.Singletons.Internal
type Endo :: Type -> Type
newtype Endo a = Endo (a ~> a)
type SEndo :: Endo a -> Type
data SEndo e where
SEndo :: Sing x -> SEndo ('Endo x)
type instance Sing = SEndo
type EndoSym0 :: (a ~> a) ~> Endo a
data EndoSym0 tf
type instance Apply EndoSym0 x = 'Endo x
$(singletonsOnly [d|
appEndo :: Endo a -> (a -> a)
appEndo (Endo x) = x
instance Semigroup (Endo a) where
Endo x <> Endo y = Endo (x . y)
instance Monoid (Endo a) where
mempty = Endo id
|])
$(singletons [d|
newtype MaxInternal a = MaxInternal { getMaxInternal :: Maybe a }
newtype MinInternal a = MinInternal { getMinInternal :: Maybe a }
|])
$(singletonsOnly [d|
instance Ord a => Semigroup (MaxInternal a) where
m <> MaxInternal Nothing = m
MaxInternal Nothing <> n = n
(MaxInternal m@(Just x)) <> (MaxInternal n@(Just y))
= if x >= y then MaxInternal m else MaxInternal n
instance Ord a => Monoid (MaxInternal a) where
mempty = MaxInternal Nothing
instance Ord a => Semigroup (MinInternal a) where
m <> MinInternal Nothing = m
MinInternal Nothing <> n = n
(MinInternal m@(Just x)) <> (MinInternal n@(Just y))
= if x <= y then MinInternal m else MinInternal n
instance Ord a => Monoid (MinInternal a) where
mempty = MinInternal Nothing
|])
$