| Copyright | (c) Alexey Kuleshevich 2020 | 
|---|---|
| License | BSD3 | 
| Maintainer | Alexey Kuleshevich <alexey@kuleshevi.ch> | 
| Stability | experimental | 
| Portability | non-portable | 
| Safe Haskell | None | 
| Language | Haskell2010 | 
Data.Prim
Description
Synopsis
- class Prim a
 - newtype Atom a = Atom {
- unAtom :: a
 
 - class (Prim a, Eq a) => Atomic a
 - class Atomic a => AtomicCount a
 - class (Bits a, Atomic a) => AtomicBits a
 - class MonadThrow m => MonadPrim s m | m -> s
 - type RW = RealWorld
 - data RealWorld
 - data ST s a
 - runST :: (forall s. ST s a) -> a
 - showsType :: Typeable t => proxy t -> ShowS
 - byteCount :: forall e. Prim e => e -> Count Word8
 - byteCountType :: forall e. Prim e => Count Word8
 - byteCountProxy :: forall proxy e. Prim e => proxy e -> Count Word8
 - alignment :: forall e. Prim e => e -> Int
 - alignmentType :: forall e. Prim e => Int
 - alignmentProxy :: forall proxy e. Prim e => proxy e -> Int
 - newtype Count e = Count {}
 - unCountBytes :: Prim e => Count e -> Int
 - toByteCount :: Prim e => Count e -> Count Word8
 - unCountBytes# :: Prim e => Count e -> Int#
 - fromByteCount :: forall e. Prim e => Count Word8 -> Count e
 - fromByteCountRem :: forall e. Prim e => Count Word8 -> (Count e, Count Word8)
 - countToOff :: Count e -> Off e
 - countToByteOff :: Prim e => Count e -> Off Word8
 - countForType :: Count e -> e -> Count e
 - countForProxyTypeOf :: Count e -> proxy e -> Count e
 - newtype Off e = Off {}
 - unOffBytes :: Prim e => Off e -> Int
 - toByteOff :: Prim e => Off e -> Off Word8
 - unOffBytes# :: Prim e => Off e -> Int#
 - fromByteOff :: forall e. Prim e => Off Word8 -> Off e
 - fromByteOffRem :: forall e. Prim e => Off Word8 -> (Off e, Off Word8)
 - offToCount :: Off e -> Count e
 - offToByteCount :: Prim e => Off e -> Count Word8
 - offForType :: Off e -> e -> Off e
 - offForProxyTypeOf :: Off e -> proxy e -> Off e
 - prefetchValue0 :: MonadPrim s m => a -> m ()
 - prefetchValue1 :: MonadPrim s m => a -> m ()
 - prefetchValue2 :: MonadPrim s m => a -> m ()
 - prefetchValue3 :: MonadPrim s m => a -> m ()
 - module Data.Word
 - module Data.Int
 - data Ptr a
 - data ForeignPtr a
 - class Typeable (a :: k)
 - data Proxy (t :: k) = Proxy
 - module Data.Coerce
 - (#.) :: forall a b c proxy. Coercible b c => proxy b c -> (a -> b) -> a -> c
 - (.#) :: forall a b c proxy. Coercible b c => (a -> b) -> proxy b c -> a -> c
 - module Data.Semigroup
 - class Semigroup a => Monoid a where
 - newtype Ap (f :: k -> Type) (a :: k) = Ap {
- getAp :: f a
 
 - newtype Dual a = Dual {
- getDual :: a
 
 - newtype Endo a = Endo {
- appEndo :: a -> a
 
 - newtype All = All {}
 - newtype Any = Any {}
 - newtype Sum a = Sum {
- getSum :: a
 
 - newtype Product a = Product {
- getProduct :: a
 
 - newtype Alt (f :: k -> Type) (a :: k) = Alt {
- getAlt :: f a
 
 
Documentation
Invariants:
- Reading should never fail on memory that contains only zeros
 - Writing should always overwrite all of the bytes allocated for the element. In other words, writing to a dirty (uninitilized) region of memory should never leave any garbage around. For example, if a type requires 31 bytes of memory then on any write all 31 bytes must be overwritten.
 - A single thread write/read sequence must always roundtrip
 - This is not a class for serialization, therefore memory layout of unpacked datatype
   is selfcontained in 
Primclass and representation is not expected to stay the same between different versions of software. Primitive types likeInt,Word,Charare an exception to this rule for obvious reasons. 
Instances
Instances
class (Prim a, Eq a) => Atomic a Source #
Instances
class Atomic a => AtomicCount a Source #
Instances
class (Bits a, Atomic a) => AtomicBits a Source #
Instances
class MonadThrow m => MonadPrim s m | m -> s Source #
Minimal complete definition
Instances
| MonadPrim RealWorld IO Source # | |
| MonadPrim s m => MonadPrim s (MaybeT m) Source # | |
| MonadPrim s (ST s) Source # | |
| MonadPrim s m => MonadPrim s (WriterT w m) Source # | |
| MonadPrim s m => MonadPrim s (SelectT r m) Source # | |
| (Monoid w, MonadPrim s m) => MonadPrim s (AccumT w m) Source # | |
| (Monoid w, MonadPrim s m) => MonadPrim s (WriterT w m) Source # | |
| (Monoid w, MonadPrim s m) => MonadPrim s (WriterT w m) Source # | |
| MonadPrim s m => MonadPrim s (StateT st m) Source # | |
| MonadPrim s m => MonadPrim s (StateT st m) Source # | |
| MonadPrim s m => MonadPrim s (ReaderT r m) Source # | |
| MonadPrim s m => MonadPrim s (IdentityT m) Source # | |
| (e ~ SomeException, MonadPrim s m) => MonadPrim s (ExceptT e m) Source # | |
| MonadPrim s m => MonadPrim s (ContT r m) Source # | |
| MonadPrim s m => MonadPrim s (RWST r w st m) Source # | |
| (Monoid w, MonadPrim s m) => MonadPrim s (RWST r w st m) Source # | |
| (Monoid w, MonadPrim s m) => MonadPrim s (RWST r w st m) Source # | |
RealWorld is deeply magical.  It is primitive, but it is not
         unlifted (hence ptrArg).  We never manipulate values of type
         RealWorld; it's only used in the type system, to parameterise State#. 
Instances
| MonadPrimBase RealWorld IO Source # | |
| MonadUnliftPrim RealWorld IO Source # | |
Defined in Control.Prim.Monad.Internal Methods withRunInST :: ((forall a. IO a -> ST RealWorld a) -> ST RealWorld b) -> IO b Source # runInPrimBase1 :: (a -> IO b) -> ((a -> State# RealWorld -> (# State# RealWorld, b #)) -> State# RealWorld -> (# State# RealWorld, c #)) -> IO c Source # runInPrimBase2 :: (a -> IO b) -> (c -> IO d) -> ((a -> State# RealWorld -> (# State# RealWorld, b #)) -> (c -> State# RealWorld -> (# State# RealWorld, d #)) -> State# RealWorld -> (# State# RealWorld, e #)) -> IO e Source #  | |
| MonadPrim RealWorld IO Source # | |
The strict ST monad.
 The ST monad allows for destructive updates, but is escapable (unlike IO).
 A computation of type  returns a value of type ST s aa, and
 execute in "thread" s. The s parameter is either
- an uninstantiated type variable (inside invocations of 
runST), or RealWorld(inside invocations ofstToIO).
It serves to keep the internal states of different invocations
 of runST separate from each other and from invocations of
 stToIO.
The >>= and >> operations are strict in the state (though not in
 values stored in the state).  For example,
runST (writeSTRef _|_ v >>= f) = _|_Instances
runST :: (forall s. ST s a) -> a #
Return the value computed by a state thread.
 The forall ensures that the internal state used by the ST
 computation is inaccessible to the rest of the program.
showsType :: Typeable t => proxy t -> ShowS Source #
Helper function that converts a type into a string
Since: 0.3.0
Prim type size
byteCount :: forall e. Prim e => e -> Count Word8 Source #
Get the size of the data type in bytes. Argument is not evaluated.
>>>import Data.Prim>>>byteCount (Just 'a')Count {unCount = 5}
Since: 0.1.0
byteCountType :: forall e. Prim e => Count Word8 Source #
Same as sizeOf, except that the type can be supplied as a type level argument
>>>:set -XTypeApplications>>>import Data.Prim>>>byteCountType @Int64Count {unCount = 8}
Since: 0.1.0
Prim type alignment
alignment :: forall e. Prim e => e -> Int Source #
Get the alignemnt of the type in bytes. Argument is not evaluated.
Since: 0.1.0
alignmentType :: forall e. Prim e => Int Source #
Same as alignment, except that the type can be supplied with TypeApplications
>>>:set -XTypeApplications>>>import Data.Prim>>>alignmentType @Int324
Since: 0.1.0
alignmentProxy :: forall proxy e. Prim e => proxy e -> Int Source #
Count
Number of elements
Instances
unCountBytes :: Prim e => Count e -> Int Source #
Covert an element count to number of bytes it coresponds to as an Int. See
 toByteCount for preserving the Count wrapper.
Since: 0.1.0
fromByteCount :: forall e. Prim e => Count Word8 -> Count e Source #
Compute how many elements of type e can fit in the supplied number of bytes.
Since: 0.1.0
countToOff :: Count e -> Off e Source #
Cast a count to an offset of the same type
Since: 0.2.0
countForType :: Count e -> e -> Count e Source #
Restrict type argument of Count to the same type as the second argument, which
 itself is not evaluated
Since: 0.2.0
countForProxyTypeOf :: Count e -> proxy e -> Count e Source #
Helper noop function that restricts Count to the type of proxy
Since: 0.2.0
Offset
Offset in number of elements
Instances
toByteOff :: Prim e => Off e -> Off Word8 Source #
Compute byte offset from an offset of Prim type
>>>toByteOff (10 :: Off Word64)Off {unOff = 80}
Since: 0.1.0
offToCount :: Off e -> Count e Source #
Cast an offset to count. Useful for dealing with regions.
>>>import Data.Prim>>>let totalCount = Count 10 :: Count Word>>>let startOffset = Off 4 :: Off Word>>>totalCount - offToCount startOffsetCount {unCount = 6}
Since: 0.2.0
offToByteCount :: Prim e => Off e -> Count Word8 Source #
Convert an offset in elements to count in bytres.
Since: 0.2.0
offForType :: Off e -> e -> Off e Source #
Restrict type argument of Off to the same type as the second argument, which itself
 is not evaluated
Since: 0.2.0
offForProxyTypeOf :: Off e -> proxy e -> Off e Source #
Helper noop function that restricts Offset to the type of proxy
Since: 0.2.0
Prefetch
prefetchValue0 :: MonadPrim s m => a -> m () Source #
prefetchValue1 :: MonadPrim s m => a -> m () Source #
prefetchValue2 :: MonadPrim s m => a -> m () Source #
prefetchValue3 :: MonadPrim s m => a -> m () Source #
Re-export
module Data.Word
module Data.Int
A value of type  represents a pointer to an object, or an
 array of objects, which may be marshalled to or from Haskell values
 of type Ptr aa.
The type a will often be an instance of class
 Storable which provides the marshalling operations.
 However this is not essential, and you can provide your own operations
 to access the pointer.  For example you might write small foreign
 functions to get or set the fields of a C struct.
Instances
| NFData1 Ptr | Since: deepseq-1.4.3.0  | 
Defined in Control.DeepSeq  | |
| IArray UArray (Ptr a) | |
Defined in Data.Array.Base Methods bounds :: Ix i => UArray i (Ptr a) -> (i, i) # numElements :: Ix i => UArray i (Ptr a) -> Int unsafeArray :: Ix i => (i, i) -> [(Int, Ptr a)] -> UArray i (Ptr a) unsafeAt :: Ix i => UArray i (Ptr a) -> Int -> Ptr a unsafeReplace :: Ix i => UArray i (Ptr a) -> [(Int, Ptr a)] -> UArray i (Ptr a) unsafeAccum :: Ix i => (Ptr a -> e' -> Ptr a) -> UArray i (Ptr a) -> [(Int, e')] -> UArray i (Ptr a) unsafeAccumArray :: Ix i => (Ptr a -> e' -> Ptr a) -> Ptr a -> (i, i) -> [(Int, e')] -> UArray i (Ptr a)  | |
| Generic1 (URec (Ptr ()) :: k -> Type) | Since: base-4.9.0.0  | 
| Eq (Ptr a) | Since: base-2.1  | 
| Ord (Ptr a) | Since: base-2.1  | 
| Show (Ptr a) | Since: base-2.1  | 
| Foldable (UAddr :: Type -> Type) | Since: base-4.9.0.0  | 
Defined in Data.Foldable Methods fold :: Monoid m => UAddr m -> m # foldMap :: Monoid m => (a -> m) -> UAddr a -> m # foldMap' :: Monoid m => (a -> m) -> UAddr a -> m # foldr :: (a -> b -> b) -> b -> UAddr a -> b # foldr' :: (a -> b -> b) -> b -> UAddr a -> b # foldl :: (b -> a -> b) -> b -> UAddr a -> b # foldl' :: (b -> a -> b) -> b -> UAddr a -> b # foldr1 :: (a -> a -> a) -> UAddr a -> a # foldl1 :: (a -> a -> a) -> UAddr a -> a # elem :: Eq a => a -> UAddr a -> Bool # maximum :: Ord a => UAddr a -> a # minimum :: Ord a => UAddr a -> a #  | |
| Traversable (UAddr :: Type -> Type) | Since: base-4.9.0.0  | 
| NFData (Ptr a) | Since: deepseq-1.4.2.0  | 
Defined in Control.DeepSeq  | |
| Prim (Ptr a) Source # | |
Defined in Data.Prim.Class Methods toPrimBase :: Ptr a -> PrimBase (Ptr a) Source # fromPrimBase :: PrimBase (Ptr a) -> Ptr a Source # sizeOf# :: Proxy# (Ptr a) -> Int# Source # alignment# :: Proxy# (Ptr a) -> Int# Source # indexByteOffByteArray# :: ByteArray# -> Int# -> Ptr a Source # indexByteArray# :: ByteArray# -> Int# -> Ptr a Source # indexOffAddr# :: Addr# -> Int# -> Ptr a Source # readByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Ptr a #) Source # readMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Ptr a #) Source # readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Ptr a #) Source # writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> Ptr a -> State# s -> State# s Source # writeMutableByteArray# :: MutableByteArray# s -> Int# -> Ptr a -> State# s -> State# s Source # writeOffAddr# :: Addr# -> Int# -> Ptr a -> State# s -> State# s Source # setMutableByteArray# :: MutableByteArray# s -> Int# -> Int# -> Ptr a -> State# s -> State# s Source # setOffAddr# :: Addr# -> Int# -> Int# -> Ptr a -> State# s -> State# s Source #  | |
| Atomic (Ptr a) Source # | |
Defined in Data.Prim.Atomic Methods atomicReadMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Ptr a #) Source # atomicWriteMutableByteArray# :: MutableByteArray# s -> Int# -> Ptr a -> State# s -> State# s Source # atomicReadOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Ptr a #) Source # atomicWriteOffAddr# :: Addr# -> Int# -> Ptr a -> State# s -> State# s Source # casMutableByteArray# :: MutableByteArray# s -> Int# -> Ptr a -> Ptr a -> State# s -> (# State# s, Ptr a #) Source # casOffAddr# :: Addr# -> Int# -> Ptr a -> Ptr a -> State# s -> (# State# s, Ptr a #) Source # casBoolMutableByteArray# :: MutableByteArray# s -> Int# -> Ptr a -> Ptr a -> State# s -> (# State# s, Bool #) Source # casBoolOffAddr# :: Addr# -> Int# -> Ptr a -> Ptr a -> State# s -> (# State# s, Bool #) Source # atomicModifyMutableByteArray# :: MutableByteArray# s -> Int# -> (Ptr a -> (# Ptr a, b #)) -> State# s -> (# State# s, b #) Source # atomicModifyOffAddr# :: Addr# -> Int# -> (Ptr a -> (# Ptr a, b #)) -> State# s -> (# State# s, b #) Source #  | |
| MArray (STUArray s) (Ptr a) (ST s) | |
Defined in Data.Array.Base Methods getBounds :: Ix i => STUArray s i (Ptr a) -> ST s (i, i) # getNumElements :: Ix i => STUArray s i (Ptr a) -> ST s Int newArray :: Ix i => (i, i) -> Ptr a -> ST s (STUArray s i (Ptr a)) # newArray_ :: Ix i => (i, i) -> ST s (STUArray s i (Ptr a)) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STUArray s i (Ptr a)) unsafeRead :: Ix i => STUArray s i (Ptr a) -> Int -> ST s (Ptr a) unsafeWrite :: Ix i => STUArray s i (Ptr a) -> Int -> Ptr a -> ST s ()  | |
| Functor (URec (Ptr ()) :: Type -> Type) | Since: base-4.9.0.0  | 
| Eq (URec (Ptr ()) p) | Since: base-4.9.0.0  | 
| Ord (URec (Ptr ()) p) | Since: base-4.9.0.0  | 
Defined in GHC.Generics Methods compare :: URec (Ptr ()) p -> URec (Ptr ()) p -> Ordering # (<) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # (<=) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # (>) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # (>=) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # max :: URec (Ptr ()) p -> URec (Ptr ()) p -> URec (Ptr ()) p # min :: URec (Ptr ()) p -> URec (Ptr ()) p -> URec (Ptr ()) p #  | |
| Generic (URec (Ptr ()) p) | Since: base-4.9.0.0  | 
| data URec (Ptr ()) (p :: k) | Used for marking occurrences of  Since: base-4.9.0.0  | 
| type Rep1 (URec (Ptr ()) :: k -> Type) | |
Defined in GHC.Generics  | |
| type PrimBase (Ptr a) Source # | |
Defined in Data.Prim.Class  | |
| type SizeOf (Ptr a) Source # | |
Defined in Data.Prim.Class  | |
| type Alignment (Ptr a) Source # | |
Defined in Data.Prim.Class  | |
| type Rep (URec (Ptr ()) p) | |
Defined in GHC.Generics  | |
data ForeignPtr a #
The type ForeignPtr represents references to objects that are
 maintained in a foreign language, i.e., that are not part of the
 data structures usually managed by the Haskell storage manager.
 The essential difference between ForeignPtrs and vanilla memory
 references of type Ptr a is that the former may be associated
 with finalizers. A finalizer is a routine that is invoked when
 the Haskell storage manager detects that - within the Haskell heap
 and stack - there are no more references left that are pointing to
 the ForeignPtr.  Typically, the finalizer will, then, invoke
 routines in the foreign language that free the resources bound by
 the foreign object.
The ForeignPtr is parameterised in the same way as Ptr.  The
 type argument of ForeignPtr should normally be an instance of
 class Storable.
Instances
| Eq (ForeignPtr a) | Since: base-2.1  | 
Defined in GHC.ForeignPtr  | |
| Ord (ForeignPtr a) | Since: base-2.1  | 
Defined in GHC.ForeignPtr Methods compare :: ForeignPtr a -> ForeignPtr a -> Ordering # (<) :: ForeignPtr a -> ForeignPtr a -> Bool # (<=) :: ForeignPtr a -> ForeignPtr a -> Bool # (>) :: ForeignPtr a -> ForeignPtr a -> Bool # (>=) :: ForeignPtr a -> ForeignPtr a -> Bool # max :: ForeignPtr a -> ForeignPtr a -> ForeignPtr a # min :: ForeignPtr a -> ForeignPtr a -> ForeignPtr a #  | |
| Show (ForeignPtr a) | Since: base-2.1  | 
Defined in GHC.ForeignPtr Methods showsPrec :: Int -> ForeignPtr a -> ShowS # show :: ForeignPtr a -> String # showList :: [ForeignPtr a] -> ShowS #  | |
The class Typeable allows a concrete representation of a type to
 be calculated.
Minimal complete definition
typeRep#
Proxy is a type that holds no data, but has a phantom parameter of
 arbitrary type (or even kind). Its use is to provide type information, even
 though there is no value available of that type (or it may be too costly to
 create one).
Historically,  is a safer alternative to the
 Proxy :: Proxy a idiom.undefined :: a
>>>Proxy :: Proxy (Void, Int -> Int)Proxy
Proxy can even hold types of higher kinds,
>>>Proxy :: Proxy EitherProxy
>>>Proxy :: Proxy FunctorProxy
>>>Proxy :: Proxy complicatedStructureProxy
Constructors
| Proxy | 
Instances
| Generic1 (Proxy :: k -> Type) | Since: base-4.6.0.0  | 
| Monad (Proxy :: Type -> Type) | Since: base-4.7.0.0  | 
| Functor (Proxy :: Type -> Type) | Since: base-4.7.0.0  | 
| Applicative (Proxy :: Type -> Type) | Since: base-4.7.0.0  | 
| Foldable (Proxy :: Type -> Type) | Since: base-4.7.0.0  | 
Defined in Data.Foldable Methods fold :: Monoid m => Proxy m -> m # foldMap :: Monoid m => (a -> m) -> Proxy a -> m # foldMap' :: Monoid m => (a -> m) -> Proxy a -> m # foldr :: (a -> b -> b) -> b -> Proxy a -> b # foldr' :: (a -> b -> b) -> b -> Proxy a -> b # foldl :: (b -> a -> b) -> b -> Proxy a -> b # foldl' :: (b -> a -> b) -> b -> Proxy a -> b # foldr1 :: (a -> a -> a) -> Proxy a -> a # foldl1 :: (a -> a -> a) -> Proxy a -> a # elem :: Eq a => a -> Proxy a -> Bool # maximum :: Ord a => Proxy a -> a # minimum :: Ord a => Proxy a -> a #  | |
| Traversable (Proxy :: Type -> Type) | Since: base-4.7.0.0  | 
| Eq1 (Proxy :: Type -> Type) | Since: base-4.9.0.0  | 
| Ord1 (Proxy :: Type -> Type) | Since: base-4.9.0.0  | 
Defined in Data.Functor.Classes  | |
| Read1 (Proxy :: Type -> Type) | Since: base-4.9.0.0  | 
Defined in Data.Functor.Classes  | |
| Show1 (Proxy :: Type -> Type) | Since: base-4.9.0.0  | 
| Alternative (Proxy :: Type -> Type) | Since: base-4.9.0.0  | 
| MonadPlus (Proxy :: Type -> Type) | Since: base-4.9.0.0  | 
| NFData1 (Proxy :: Type -> Type) | Since: deepseq-1.4.3.0  | 
Defined in Control.DeepSeq  | |
| Bounded (Proxy t) | Since: base-4.7.0.0  | 
| Enum (Proxy s) | Since: base-4.7.0.0  | 
| Eq (Proxy s) | Since: base-4.7.0.0  | 
| Ord (Proxy s) | Since: base-4.7.0.0  | 
| Read (Proxy t) | Since: base-4.7.0.0  | 
| Show (Proxy s) | Since: base-4.7.0.0  | 
| Ix (Proxy s) | Since: base-4.7.0.0  | 
Defined in Data.Proxy  | |
| Generic (Proxy t) | Since: base-4.6.0.0  | 
| Semigroup (Proxy s) | Since: base-4.9.0.0  | 
| Monoid (Proxy s) | Since: base-4.7.0.0  | 
| NFData (Proxy a) | Since: deepseq-1.4.0.0  | 
Defined in Control.DeepSeq  | |
| type Rep1 (Proxy :: k -> Type) | |
| type Rep (Proxy t) | |
module Data.Coerce
(#.) :: forall a b c proxy. Coercible b c => proxy b c -> (a -> b) -> a -> c Source #
Coerce result of a function (it is also a hidden function in Data.Functor.Utils)
Since: 0.3.0
(.#) :: forall a b c proxy. Coercible b c => (a -> b) -> proxy b c -> a -> c Source #
Coerce result of a function. Flipped version of (#.)
Since: 0.3.0
module Data.Semigroup
class Semigroup a => Monoid a where #
The class of monoids (types with an associative binary operation that has an identity). Instances should satisfy the following:
- Right identity
 x<>mempty= x- Left identity
 mempty<>x = x- Associativity
 x(<>(y<>z) = (x<>y)<>zSemigrouplaw)- Concatenation
 mconcat=foldr(<>)mempty
The method names refer to the monoid of lists under concatenation, but there are many other instances.
Some types can be viewed as a monoid in more than one way,
 e.g. both addition and multiplication on numbers.
 In such cases we often define newtypes and make those instances
 of Monoid, e.g. Sum and Product.
NOTE: Semigroup is a superclass of Monoid since base-4.11.0.0.
Minimal complete definition
Methods
Identity of mappend
>>>"Hello world" <> mempty"Hello world"
An associative operation
NOTE: This method is redundant and has the default
 implementation  since base-4.11.0.0.
 Should it be implemented manually, since mappend = (<>)mappend is a synonym for
 (<>), it is expected that the two functions are defined the same
 way. In a future GHC release mappend will be removed from Monoid.
Fold a list using the monoid.
For most types, the default definition for mconcat will be
 used, but the function is included in the class definition so
 that an optimized version can be provided for specific types.
>>>mconcat ["Hello", " ", "Haskell", "!"]"Hello Haskell!"
Instances
| Monoid Ordering | Since: base-2.1  | 
| Monoid () | Since: base-2.1  | 
| Monoid All | Since: base-2.1  | 
| Monoid Any | Since: base-2.1  | 
| Monoid [a] | Since: base-2.1  | 
| Semigroup a => Monoid (Maybe a) | Lift a semigroup into  Since 4.11.0: constraint on inner  Since: base-2.1  | 
| Monoid a => Monoid (IO a) | Since: base-4.9.0.0  | 
| Monoid p => Monoid (Par1 p) | Since: base-4.12.0.0  | 
| (Ord a, Bounded a) => Monoid (Min a) | Since: base-4.9.0.0  | 
| (Ord a, Bounded a) => Monoid (Max a) | Since: base-4.9.0.0  | 
| Monoid m => Monoid (WrappedMonoid m) | Since: base-4.9.0.0  | 
Defined in Data.Semigroup Methods mempty :: WrappedMonoid m # mappend :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m # mconcat :: [WrappedMonoid m] -> WrappedMonoid m #  | |
| Semigroup a => Monoid (Option a) | Since: base-4.9.0.0  | 
| Monoid a => Monoid (Identity a) | Since: base-4.9.0.0  | 
| Monoid (First a) | Since: base-2.1  | 
| Monoid (Last a) | Since: base-2.1  | 
| Monoid a => Monoid (Dual a) | Since: base-2.1  | 
| Monoid (Endo a) | Since: base-2.1  | 
| Num a => Monoid (Sum a) | Since: base-2.1  | 
| Num a => Monoid (Product a) | Since: base-2.1  | 
| Monoid a => Monoid (Down a) | Since: base-4.11.0.0  | 
| Prim e => Monoid (UArray e) Source # | |
| Monoid (SBArray e) Source # | |
| Monoid (BArray e) Source # | |
| Monoid b => Monoid (a -> b) | Since: base-2.1  | 
| Monoid (U1 p) | Since: base-4.12.0.0  | 
| (Monoid a, Monoid b) => Monoid (a, b) | Since: base-2.1  | 
| Monoid a => Monoid (ST s a) | Since: base-4.11.0.0  | 
| Monoid (Proxy s) | Since: base-4.7.0.0  | 
| Monoid (f p) => Monoid (Rec1 f p) | Since: base-4.12.0.0  | 
| (Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) | Since: base-2.1  | 
| Monoid a => Monoid (Const a b) | Since: base-4.9.0.0  | 
| (Applicative f, Monoid a) => Monoid (Ap f a) | Since: base-4.12.0.0  | 
| Alternative f => Monoid (Alt f a) | Since: base-4.8.0.0  | 
| Monoid c => Monoid (K1 i c p) | Since: base-4.12.0.0  | 
| (Monoid (f p), Monoid (g p)) => Monoid ((f :*: g) p) | Since: base-4.12.0.0  | 
| (Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d) | Since: base-2.1  | 
| Monoid (f p) => Monoid (M1 i c f p) | Since: base-4.12.0.0  | 
| Monoid (f (g p)) => Monoid ((f :.: g) p) | Since: base-4.12.0.0  | 
| (Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e) | Since: base-2.1  | 
newtype Ap (f :: k -> Type) (a :: k) #
This data type witnesses the lifting of a Monoid into an
 Applicative pointwise.
Since: base-4.12.0.0
Instances
| Generic1 (Ap f :: k -> Type) | Since: base-4.12.0.0  | 
| Monad f => Monad (Ap f) | Since: base-4.12.0.0  | 
| Functor f => Functor (Ap f) | Since: base-4.12.0.0  | 
| MonadFail f => MonadFail (Ap f) | Since: base-4.12.0.0  | 
Defined in Data.Monoid  | |
| Applicative f => Applicative (Ap f) | Since: base-4.12.0.0  | 
| Foldable f => Foldable (Ap f) | Since: base-4.12.0.0  | 
Defined in Data.Foldable Methods fold :: Monoid m => Ap f m -> m # foldMap :: Monoid m => (a -> m) -> Ap f a -> m # foldMap' :: Monoid m => (a -> m) -> Ap f a -> m # foldr :: (a -> b -> b) -> b -> Ap f a -> b # foldr' :: (a -> b -> b) -> b -> Ap f a -> b # foldl :: (b -> a -> b) -> b -> Ap f a -> b # foldl' :: (b -> a -> b) -> b -> Ap f a -> b # foldr1 :: (a -> a -> a) -> Ap f a -> a # foldl1 :: (a -> a -> a) -> Ap f a -> a # elem :: Eq a => a -> Ap f a -> Bool # maximum :: Ord a => Ap f a -> a #  | |
| Traversable f => Traversable (Ap f) | Since: base-4.12.0.0  | 
| Alternative f => Alternative (Ap f) | Since: base-4.12.0.0  | 
| MonadPlus f => MonadPlus (Ap f) | Since: base-4.12.0.0  | 
| (Applicative f, Bounded a) => Bounded (Ap f a) | Since: base-4.12.0.0  | 
| Enum (f a) => Enum (Ap f a) | Since: base-4.12.0.0  | 
Defined in Data.Monoid  | |
| Eq (f a) => Eq (Ap f a) | Since: base-4.12.0.0  | 
| (Applicative f, Num a) => Num (Ap f a) | Since: base-4.12.0.0  | 
| Ord (f a) => Ord (Ap f a) | Since: base-4.12.0.0  | 
| Read (f a) => Read (Ap f a) | Since: base-4.12.0.0  | 
| Show (f a) => Show (Ap f a) | Since: base-4.12.0.0  | 
| Generic (Ap f a) | Since: base-4.12.0.0  | 
| (Applicative f, Semigroup a) => Semigroup (Ap f a) | Since: base-4.12.0.0  | 
| (Applicative f, Monoid a) => Monoid (Ap f a) | Since: base-4.12.0.0  | 
| Prim (f a) => Prim (Ap f a) Source # | |
Defined in Data.Prim.Class Methods toPrimBase :: Ap f a -> PrimBase (Ap f a) Source # fromPrimBase :: PrimBase (Ap f a) -> Ap f a Source # sizeOf# :: Proxy# (Ap f a) -> Int# Source # alignment# :: Proxy# (Ap f a) -> Int# Source # indexByteOffByteArray# :: ByteArray# -> Int# -> Ap f a Source # indexByteArray# :: ByteArray# -> Int# -> Ap f a Source # indexOffAddr# :: Addr# -> Int# -> Ap f a Source # readByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Ap f a #) Source # readMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Ap f a #) Source # readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Ap f a #) Source # writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> Ap f a -> State# s -> State# s Source # writeMutableByteArray# :: MutableByteArray# s -> Int# -> Ap f a -> State# s -> State# s Source # writeOffAddr# :: Addr# -> Int# -> Ap f a -> State# s -> State# s Source # setMutableByteArray# :: MutableByteArray# s -> Int# -> Int# -> Ap f a -> State# s -> State# s Source # setOffAddr# :: Addr# -> Int# -> Int# -> Ap f a -> State# s -> State# s Source #  | |
| type Rep1 (Ap f :: k -> Type) | |
Defined in Data.Monoid  | |
| type Rep (Ap f a) | |
Defined in Data.Monoid  | |
| type PrimBase (Ap f a) Source # | |
Defined in Data.Prim.Class  | |
| type SizeOf (Ap f a) Source # | |
| type Alignment (Ap f a) Source # | |
The dual of a Monoid, obtained by swapping the arguments of mappend.
>>>getDual (mappend (Dual "Hello") (Dual "World"))"WorldHello"
Instances
The monoid of endomorphisms under composition.
>>>let computation = Endo ("Hello, " ++) <> Endo (++ "!")>>>appEndo computation "Haskell""Hello, Haskell!"
Boolean monoid under conjunction (&&).
>>>getAll (All True <> mempty <> All False)False
>>>getAll (mconcat (map (\x -> All (even x)) [2,4,6,7,8]))False
Instances
Boolean monoid under disjunction (||).
>>>getAny (Any True <> mempty <> Any False)True
>>>getAny (mconcat (map (\x -> Any (even x)) [2,4,6,7,8]))True
Instances
Monoid under addition.
>>>getSum (Sum 1 <> Sum 2 <> mempty)3
Instances
Monoid under multiplication.
>>>getProduct (Product 3 <> Product 4 <> mempty)12
Constructors
| Product | |
Fields 
  | |
Instances
newtype Alt (f :: k -> Type) (a :: k) #
Monoid under <|>.
>>>getAlt (Alt (Just 12) <> Alt (Just 24))Just 12
>>>getAlt $ Alt Nothing <> Alt (Just 24)Just 24
Since: base-4.8.0.0
Instances
| Generic1 (Alt f :: k -> Type) | Since: base-4.8.0.0  | 
| Monad f => Monad (Alt f) | Since: base-4.8.0.0  | 
| Functor f => Functor (Alt f) | Since: base-4.8.0.0  | 
| Applicative f => Applicative (Alt f) | Since: base-4.8.0.0  | 
| Foldable f => Foldable (Alt f) | Since: base-4.12.0.0  | 
Defined in Data.Foldable Methods fold :: Monoid m => Alt f m -> m # foldMap :: Monoid m => (a -> m) -> Alt f a -> m # foldMap' :: Monoid m => (a -> m) -> Alt f a -> m # foldr :: (a -> b -> b) -> b -> Alt f a -> b # foldr' :: (a -> b -> b) -> b -> Alt f a -> b # foldl :: (b -> a -> b) -> b -> Alt f a -> b # foldl' :: (b -> a -> b) -> b -> Alt f a -> b # foldr1 :: (a -> a -> a) -> Alt f a -> a # foldl1 :: (a -> a -> a) -> Alt f a -> a # elem :: Eq a => a -> Alt f a -> Bool # maximum :: Ord a => Alt f a -> a # minimum :: Ord a => Alt f a -> a #  | |
| Traversable f => Traversable (Alt f) | Since: base-4.12.0.0  | 
| Alternative f => Alternative (Alt f) | Since: base-4.8.0.0  | 
| MonadPlus f => MonadPlus (Alt f) | Since: base-4.8.0.0  | 
| Enum (f a) => Enum (Alt f a) | Since: base-4.8.0.0  | 
| Eq (f a) => Eq (Alt f a) | Since: base-4.8.0.0  | 
| Num (f a) => Num (Alt f a) | Since: base-4.8.0.0  | 
| Ord (f a) => Ord (Alt f a) | Since: base-4.8.0.0  | 
Defined in Data.Semigroup.Internal  | |
| Read (f a) => Read (Alt f a) | Since: base-4.8.0.0  | 
| Show (f a) => Show (Alt f a) | Since: base-4.8.0.0  | 
| Generic (Alt f a) | Since: base-4.8.0.0  | 
| Alternative f => Semigroup (Alt f a) | Since: base-4.9.0.0  | 
| Alternative f => Monoid (Alt f a) | Since: base-4.8.0.0  | 
| Prim (f a) => Prim (Alt f a) Source # | |
Defined in Data.Prim.Class Methods toPrimBase :: Alt f a -> PrimBase (Alt f a) Source # fromPrimBase :: PrimBase (Alt f a) -> Alt f a Source # sizeOf# :: Proxy# (Alt f a) -> Int# Source # alignment# :: Proxy# (Alt f a) -> Int# Source # indexByteOffByteArray# :: ByteArray# -> Int# -> Alt f a Source # indexByteArray# :: ByteArray# -> Int# -> Alt f a Source # indexOffAddr# :: Addr# -> Int# -> Alt f a Source # readByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Alt f a #) Source # readMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Alt f a #) Source # readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Alt f a #) Source # writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> Alt f a -> State# s -> State# s Source # writeMutableByteArray# :: MutableByteArray# s -> Int# -> Alt f a -> State# s -> State# s Source # writeOffAddr# :: Addr# -> Int# -> Alt f a -> State# s -> State# s Source # setMutableByteArray# :: MutableByteArray# s -> Int# -> Int# -> Alt f a -> State# s -> State# s Source # setOffAddr# :: Addr# -> Int# -> Int# -> Alt f a -> State# s -> State# s Source #  | |
| type Rep1 (Alt f :: k -> Type) | |
Defined in Data.Semigroup.Internal  | |
| type Rep (Alt f a) | |
Defined in Data.Semigroup.Internal  | |
| type PrimBase (Alt f a) Source # | |
Defined in Data.Prim.Class  | |
| type SizeOf (Alt f a) Source # | |
| type Alignment (Alt f a) Source # | |