SimpleH-1.2: A light, clean and powerful Haskell utility library

Safe HaskellNone

Algebra.Core

Contents

Synopsis

Raw data

data ByteString

A space-efficient representation of a Word8 vector, supporting many efficient operations. A ByteString contains 8-bit characters only.

Instances of Eq, Ord, Read, Show, Data, Typeable

readFile :: FilePath -> IO ByteString

Read an entire file strictly into a ByteString. This is far more efficient than reading the characters into a String and then using pack. It also may be more efficient than opening the file and reading it using hGet.

writeFile :: FilePath -> ByteString -> IO ()

Write a ByteString to a file.

hGetContents :: Handle -> IO ByteString

Read entire handle contents strictly into a ByteString.

This function reads chunks at a time, doubling the chunksize on each read. The final buffer is then realloced to the appropriate size. For files > half of available memory, this may lead to memory exhaustion. Consider using readFile in this case.

As with hGet, the string representation in the file is assumed to be ISO-8859-1.

The Handle is closed once the contents have been read, or if an exception is thrown.

Basic union and product types

type :*: a b = (a, b)Source

type :+: a b = Either a bSource

Basic group and ring structure

Classes

class Semigroup m whereSource

The class of all types that have a binary operation. Note that the operation isn't necesarily commutative (in the case of lists, for example)

Methods

(+) :: m -> m -> mSource

Instances

Semigroup Bool 
Semigroup Double 
Semigroup Float 
Semigroup Int 
Semigroup Integer 
Semigroup () 
Semigroup Builder 
Semigroup Void 
Semigroup File 
Semigroup [a] 
Semigroup (Maybe a) 
Ord a => Semigroup (Set a) 
Semigroup (Interleave a) 
Orderable a => Semigroup (OrdList a) 
Semigroup m => Semigroup (Dual m) 
Ord a => Semigroup (Max a) 
Monoid a => Semigroup (Accum a) 
Semigroup (StrictEndo a) 
Ring a => Semigroup (Product a) 
Semigroup a => Semigroup (ZipList a) 
Ord t => Semigroup (Time t)

The Time semigroup where ta + tb == max ta tb

Semigroup b => Semigroup (a -> b) 
Ord k => Semigroup (Map k a) 
Category k => Semigroup (Endo k a) 
SubSemi b a => Semigroup (:+: a b) 
(Semigroup a, Semigroup b) => Semigroup (:*: a b) 
Semigroup a => Semigroup (Const a b) 
Semigroup (f a) => Semigroup (Backwards f a) 
Applicative m => Semigroup (ListT m a) 
(Ord t, Semigroup a) => Semigroup (Future t a) 
Ord t => Semigroup (Event t a) 
(Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c) 
(Applicative f, Semigroup (g a)) => Semigroup (:.: f g a) 
Semigroup (f b a) => Semigroup (Flip f a b) 
(Semigroup (f a), Applicative g) => Semigroup (Compose' f g a) 
Semigroup (m (a, s, Void)) => Semigroup (StateT s m a) 
Semigroup (m (a, Void, Void)) => Semigroup (ReaderT r m a) 
Semigroup (m (a, Void, w)) => Semigroup (WriterT w m a) 
Semigroup (m r) => Semigroup (ContT r m a) 
(Monoid w, Monad m) => Semigroup (ParserT w s m a) 
Semigroup (m (a, s, w)) => Semigroup (RWST r w s m a) 

class Semigroup m => Monoid m whereSource

A monoid is a semigroup with a null element such that zero + a == a + zero == a

Methods

zero :: mSource

Instances

Monoid Bool 
Monoid Double 
Monoid Float 
Monoid Int 
Monoid Integer 
Monoid () 
Monoid Builder 
Monoid Void 
Monoid [a] 
Monoid (Maybe a) 
Ord a => Monoid (Set a) 
Monoid (Interleave a) 
Orderable a => Monoid (OrdList a) 
Monoid m => Monoid (Dual m) 
(Ord a, Bounded a) => Monoid (Max a) 
Monoid a => Monoid (Accum a) 
Ring a => Monoid (Product a) 
Monoid a => Monoid (ZipList a) 
Ord t => Monoid (Time t)

The Time monoid where zero == minBound

Monoid b => Monoid (a -> b) 
Ord k => Monoid (Map k a) 
Category k => Monoid (Endo k a) 
(SubSemi b a, Monoid a) => Monoid (:+: a b) 
(Monoid a, Monoid b) => Monoid (:*: a b) 
Monoid a => Monoid (Const a b) 
Monoid (f a) => Monoid (Backwards f a) 
Applicative m => Monoid (ListT m a) 
(Ord t, Monoid a) => Monoid (Future t a) 
Ord t => Monoid (Event t a) 
(Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) 
(Applicative f, Monoid (g a)) => Monoid (:.: f g a) 
Monoid (f b a) => Monoid (Flip f a b) 
(Monoid (f a), Applicative g) => Monoid (Compose' f g a) 
Monoid (m (a, s, Void)) => Monoid (StateT s m a) 
Monoid (m (a, Void, Void)) => Monoid (ReaderT r m a) 
Monoid (m (a, Void, w)) => Monoid (WriterT w m a) 
Monoid (m r) => Monoid (ContT r m a) 
(Monoid w, Monad m) => Monoid (ParserT w s m a) 
Monoid (m (a, s, w)) => Monoid (RWST r w s m a) 

class Monoid m => Ring m whereSource

Methods

one :: mSource

(*) :: m -> m -> mSource

Instances

Ring Bool 
Ring Double 
Ring Float 
Ring Int 
Ring Integer 
Monoid a => Ring [a] 
(Ord a, Monoid a) => Ring (Set a) 
Ring m => Ring (Dual m) 
(Ord a, Bounded a) => Ring (Max a) 
Ord t => Ring (Time t)

The Time ring where (*) == min and one == maxBound

Ring b => Ring (a -> b) 
(Ring a, Ring b) => Ring (:*: a b) 
Ring (f a) => Ring (Backwards f a) 
Ring (m (a, s, Void)) => Ring (StateT s m a) 
Ring (m (a, Void, Void)) => Ring (ReaderT r m a) 
Ring (m (a, Void, w)) => Ring (WriterT w m a) 
Ring (m r) => Ring (ContT r m a) 
Ring (m (a, s, w)) => Ring (RWST r w s m a) 

class (Semigroup a, Semigroup b) => SubSemi a b whereSource

Methods

cast :: b -> aSource

Instances

Monoid a => SubSemi a Void 
Monoid a => SubSemi a () 
(Foldable f, Semigroup (Sized f a), Monoid n, Num n) => SubSemi n (Sized f a) 

class Unit f whereSource

Methods

pure :: a -> f aSource

Instances

Unit [] 
Unit IO 
Unit Maybe 
Unit Tree 
Unit Interleave 
Unit OrdList 
Unit Id 
Unit Accum 
Unit ZipTree 
Unit ZipList 
Unit TimeVal 
Unit Time 
Unit ((->) b) 
Unit (Either a) 
Monoid w => Unit ((,) w) 
Monoid a => Unit (Const a) 
Unit f => Unit (Backwards f) 
Unit m => Unit (MaybeT m) 
Unit m => Unit (TreeT m) 
Unit m => Unit (ListT m) 
Ord t => Unit (Future t) 
Ord t => Unit (Reactive t) 
Ord t => Unit (Event t) 
(Unit f, Unit g) => Unit (:**: f g) 
(Unit f, Unit g) => Unit (:.: f g) 
(Unit f, Unit g) => Unit (Compose' f g) 
Unit m => Unit (StateT s m) 
Unit m => Unit (ReaderT r m) 
(Unit m, Monoid w) => Unit (WriterT w m) 
Unit m => Unit (ContT r m) 
Unit m => Unit (EitherT e m) 
(Unit m, Monoid w) => Unit (ParserT w s m) 
(Unit f, Monoid w) => Unit (RWST r w s f) 

Common monoids

Control monoids

newtype Endo k a Source

A monoid on category endomorphisms under composition

Constructors

Endo 

Fields

runEndo :: k a a
 

Instances

Category k => Monoid (Endo k a) 
Category k => Semigroup (Endo k a) 
Isomorphic (k a a) (k b b) (Endo k a) (Endo k b) 

newtype StrictEndo a Source

Constructors

StrictEndo 

Fields

runStrictEndo :: a -> a
 

Instances

Meta-monoids

newtype Dual m Source

The dual of a monoid is the same as the original, with arguments reversed

Constructors

Dual 

Fields

getDual :: m
 

Instances

Isomorphic a b (Dual a) (Dual b) 
Ring m => Ring (Dual m) 
Monoid m => Monoid (Dual m) 
Semigroup m => Semigroup (Dual m) 

newtype Product a Source

The Product monoid

Constructors

Product 

Fields

getProduct :: a
 

Instances

Ring a => Monoid (Product a) 
Ring a => Semigroup (Product a) 

Accumulating monoids

newtype OrdList a Source

An ordered list. The semigroup instance merges two lists so that the result remains in ascending order.

Constructors

OrdList 

Fields

getOrdList :: [a]
 

newtype Accum a Source

A monoid on Maybes, where the sum is the leftmost non-Nothing value.

Constructors

Accum 

Fields

getAccum :: Maybe a
 

Instances

newtype Max a Source

The Max monoid, where (+) =~ max

Constructors

Max 

Fields

getMax :: a
 

Instances

Isomorphic a b (Max a) (Max b) 
Bounded a => Bounded (Max a) 
Eq a => Eq (Max a) 
Ord a => Ord (Max a) 
Show a => Show (Max a) 
Ord t => Orderable (Max t) 
(Ord a, Bounded a) => Ring (Max a) 
(Ord a, Bounded a) => Monoid (Max a) 
Ord a => Semigroup (Max a) 

newtype Id a Source

The Identity Functor

Constructors

Id 

Fields

getId :: a
 

Fundamental control operations

class Category k whereSource

Methods

id :: k a aSource

(.) :: k b c -> k a b -> k a cSource

Instances

Category (->) 
Monad m => Category (Kleisli m) 
Monad m => Category (StateA m) 
Category k => Category (ListA k) 
(Monoid w, Monad m) => Category (ParserA w m) 

(<<<) :: Category k => k b c -> k a b -> k a cSource

(>>>) :: Category k => k a b -> k b c -> k a cSource

(+++) :: Split k => (a -> k c c) -> (b -> k d d) -> (a :+: b) -> k (c, d) (c, d)Source

Splitting and Choosing

class Category k => Choice k whereSource

Methods

(<|>) :: k a c -> k b c -> k (a :+: b) cSource

Instances

Choice (->) 
Monad m => Choice (Kleisli m) 
Monad m => Choice (StateA m) 
Arrow k => Choice (ListA k) 
(Monoid w, Monad m) => Choice (ParserA w m) 

class Category k => Split k whereSource

Methods

(<#>) :: k a c -> k b d -> k (a, b) (c, d)Source

Instances

Split (->) 
Monad m => Split (Kleisli m) 
Monad m => Split (StateA m) 
Arrow k => Split (ListA k) 
(Monoid w, Monad m) => Split (ParserA w m) 

Misc functions

const :: Unit m => a -> m aSource

(&) :: a -> (a -> b) -> bSource

is :: a -> (a -> Bool) -> BoolSource

fix :: (a -> a) -> aSource

first :: Split k => k a b -> k (a, c) (b, c)Source

second :: Split k => k a b -> k (c, a) (c, b)Source

ifThenElse :: Bool -> a -> a -> aSource

bool :: a -> a -> Bool -> aSource

guard :: (Unit m, Monoid (m ())) => Bool -> m ()Source

unit :: Unit m => m ()Source

when :: Unit m => Bool -> m () -> m ()Source

unless :: Unit m => Bool -> m () -> m ()Source

tailSafe :: [a] -> [a]Source

headDef :: a -> [a] -> aSource

rmod :: (RealFrac m, Ring m) => m -> m -> mSource

inside :: Ord t => t -> t -> t -> BoolSource

swap :: (a, b) -> (b, a)Source

Lazily ordering values

class Ord t => Orderable t whereSource

Methods

inOrder :: t -> t -> (t, t, Bool)Source

Instances

Ord t => Orderable (Max t) 
Ord t => Orderable (Time t) 
Ord t => Orderable (Future t a) 

comparing :: Ord a => (b -> a) -> b -> b -> Ordering

 comparing p x y = compare (p x) (p y)

Useful combinator for use in conjunction with the xxxBy family of functions from Data.List, for example:

   ... sortBy (comparing fst) ...

insertOrd :: Orderable t => t -> [t] -> [t]Source

The rest is imported from the Prelude

module Prelude