neural-0.3.0.0: Neural Networks in native Haskell

Copyright(c) Lars Brünjes, 2016
LicenseMIT
Maintainerbrunjlar@gmail.com
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Data.MyPrelude

Description

This module simply reexports a selection of commonly used standard types and functions.

Synopsis

Documentation

class NFData a where

A class of types that can be fully evaluated.

Since: 1.1.0.0

Minimal complete definition

Nothing

Methods

rnf :: a -> ()

rnf should reduce its argument to normal form (that is, fully evaluate all sub-components), and then return '()'.

Generic NFData deriving

Starting with GHC 7.2, you can automatically derive instances for types possessing a Generic instance.

{-# LANGUAGE DeriveGeneric #-}

import GHC.Generics (Generic)
import Control.DeepSeq

data Foo a = Foo a String
             deriving (Eq, Generic)

instance NFData a => NFData (Foo a)

data Colour = Red | Green | Blue
              deriving Generic

instance NFData Colour

Starting with GHC 7.10, the example above can be written more concisely by enabling the new DeriveAnyClass extension:

{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}

import GHC.Generics (Generic)
import Control.DeepSeq

data Foo a = Foo a String
             deriving (Eq, Generic, NFData)

data Colour = Red | Green | Blue
              deriving (Generic, NFData)

Compatibility with previous deepseq versions

Prior to version 1.4.0.0, the default implementation of the rnf method was defined as

rnf a = seq a ()

However, starting with deepseq-1.4.0.0, the default implementation is based on DefaultSignatures allowing for more accurate auto-derived NFData instances. If you need the previously used exact default rnf method implementation semantics, use

instance NFData Colour where rnf x = seq x ()

or alternatively

{-# LANGUAGE BangPatterns #-}
instance NFData Colour where rnf !_ = ()

Instances

NFData Bool 
NFData Char 
NFData Double 
NFData Float 
NFData Int 
NFData Int8 
NFData Int16 
NFData Int32 
NFData Int64 
NFData Integer 
NFData Word 
NFData Word8 
NFData Word16 
NFData Word32 
NFData Word64 
NFData TypeRep

NOTE: Only defined for base-4.8.0.0 and later

Since: 1.4.0.0

NFData () 
NFData Void

Defined as rnf = absurd.

Since: 1.4.0.0

NFData Unique

Since: 1.4.0.0

NFData Natural

Since: 1.4.0.0

NFData Version

Since: 1.3.0.0

NFData ThreadId

Since: 1.4.0.0

NFData CChar

Since: 1.4.0.0

NFData CSChar

Since: 1.4.0.0

NFData CUChar

Since: 1.4.0.0

NFData CShort

Since: 1.4.0.0

NFData CUShort

Since: 1.4.0.0

NFData CInt

Since: 1.4.0.0

NFData CUInt

Since: 1.4.0.0

NFData CLong

Since: 1.4.0.0

NFData CULong

Since: 1.4.0.0

NFData CLLong

Since: 1.4.0.0

NFData CULLong

Since: 1.4.0.0

NFData CFloat

Since: 1.4.0.0

NFData CDouble

Since: 1.4.0.0

NFData CPtrdiff

Since: 1.4.0.0

NFData CSize

Since: 1.4.0.0

NFData CWchar

Since: 1.4.0.0

NFData CSigAtomic

Since: 1.4.0.0

NFData CClock

Since: 1.4.0.0

NFData CTime

Since: 1.4.0.0

NFData CUSeconds

Since: 1.4.0.0

NFData CSUSeconds

Since: 1.4.0.0

NFData CFile

Since: 1.4.0.0

NFData CFpos

Since: 1.4.0.0

NFData CJmpBuf

Since: 1.4.0.0

NFData CIntPtr

Since: 1.4.0.0

NFData CUIntPtr

Since: 1.4.0.0

NFData CIntMax

Since: 1.4.0.0

NFData CUIntMax

Since: 1.4.0.0

NFData All

Since: 1.4.0.0

NFData Any

Since: 1.4.0.0

NFData TyCon

NOTE: Only defined for base-4.8.0.0 and later

Since: 1.4.0.0

NFData Fingerprint

Since: 1.4.0.0

NFData ByteString 
NFData ByteString 
NFData IntSet 
NFData Doc 
NFData TextDetails 
NFData LocalTime 
NFData ZonedTime 
NFData TimeOfDay 
NFData TimeZone 
NFData UTCTime 
NFData NominalDiffTime 
NFData Day 
NFData a => NFData [a] 
(Integral a, NFData a) => NFData (Ratio a) 
NFData a => NFData (IntMap a) 
NFData (StableName a)

Since: 1.4.0.0

NFData a => NFData (Identity a)

Since: 1.4.0.0

NFData (Fixed a)

Since: 1.3.0.0

NFData a => NFData (Complex a) 
NFData a => NFData (ZipList a)

Since: 1.4.0.0

NFData a => NFData (Dual a)

Since: 1.4.0.0

NFData a => NFData (Sum a)

Since: 1.4.0.0

NFData a => NFData (Product a)

Since: 1.4.0.0

NFData a => NFData (First a)

Since: 1.4.0.0

NFData a => NFData (Last a)

Since: 1.4.0.0

NFData a => NFData (Down a)

Since: 1.4.0.0

NFData a => NFData (Maybe a) 
NFData a => NFData (Digit a) 
NFData a => NFData (Node a) 
NFData a => NFData (Elem a) 
NFData a => NFData (FingerTree a) 
NFData a => NFData (Set a) 
NFData a => NFData (Tree a) 
NFData a => NFData (Seq a) 
NFData a => NFData (Vector a) 
NFData (Vector a) 
NFData (Vector a) 
NFData (Vector a) 
NFData a => NFData (HashSet a) 
NFData (IVar a) 
NFData a => NFData (Probability a) 
NFData a => NFData (NonEmpty a) 
NFData m => NFData (WrappedMonoid m) 
NFData a => NFData (Option a) 
NFData a => NFData (Min a) 
NFData a => NFData (Max a) 
NFData a => NFData (Last a) 
NFData a => NFData (First a) 
NFData (a -> b)

This instance is for convenience and consistency with seq. This assumes that WHNF is equivalent to NF for functions.

Since: 1.3.0.0

(NFData a, NFData b) => NFData (Either a b) 
(NFData a, NFData b) => NFData (a, b) 
(Ix a, NFData a, NFData b) => NFData (Array a b) 
NFData a => NFData (Const a b)

Since: 1.4.0.0

NFData (Proxy * a)

Since: 1.4.0.0

(NFData k, NFData a) => NFData (Map k a) 
(NFData k, NFData v) => NFData (HashMap k v) 
NFData (MVector s a) 
NFData (MVector s a) 
NFData (MVector s a) 
(NFData a, NFData b) => NFData (Arg a b) 
(NFData k, NFData v) => NFData (Leaf k v) 
NFData a => NFData (Vector n a) 
NFData (Component f g) 
(NFData a, NFData b, NFData c) => NFData (a, b, c) 
NFData b => NFData (Tagged k s b) 
NFData a => NFData (Matrix m n a) 
(NFData (s a), NFData (t a)) => NFData (Pair s t a) 
(NFData a, NFData b, NFData c, NFData d) => NFData (a, b, c, d) 
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5) => NFData (a1, a2, a3, a4, a5) 
NFData (Model f g a b c) 
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6) => NFData (a1, a2, a3, a4, a5, a6) 
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7) => NFData (a1, a2, a3, a4, a5, a6, a7) 
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7, NFData a8) => NFData (a1, a2, a3, a4, a5, a6, a7, a8) 
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7, NFData a8, NFData a9) => NFData (a1, a2, a3, a4, a5, a6, a7, a8, a9) 

deepseq :: NFData a => a -> b -> b

deepseq: fully evaluates the first argument, before returning the second.

The name deepseq is used to illustrate the relationship to seq: where seq is shallow in the sense that it only evaluates the top level of its argument, deepseq traverses the entire data structure evaluating it completely.

deepseq can be useful for forcing pending exceptions, eradicating space leaks, or forcing lazy I/O to happen. It is also useful in conjunction with parallel Strategies (see the parallel package).

There is no guarantee about the ordering of evaluation. The implementation may evaluate the components of the structure in any order or in parallel. To impose an actual order on evaluation, use pseq from Control.Parallel in the parallel package.

Since: 1.1.0.0

force :: NFData a => a -> a

a variant of deepseq that is useful in some circumstances:

force x = x `deepseq` x

force x fully evaluates x, and then returns it. Note that force x only performs evaluation when the value of force x itself is demanded, so essentially it turns shallow evaluation into deep evaluation.

force can be conveniently used in combination with ViewPatterns:

{-# LANGUAGE BangPatterns, ViewPatterns #-}
import Control.DeepSeq

someFun :: ComplexData -> SomeResult
someFun (force -> !arg) = {- 'arg' will be fully evaluated -}

Another useful application is to combine force with evaluate in order to force deep evaluation relative to other IO operations:

import Control.Exception (evaluate)
import Control.DeepSeq

main = do
  result <- evaluate $ force $ pureComputation
  {- 'result' will be fully evaluated at this point -}
  return ()

Since: 1.2.0.0

(&) :: a -> (a -> b) -> b infixl 1

& is a reverse application operator. This provides notational convenience. Its precedence is one higher than that of the forward application operator $, which allows & to be nested in $.

Since: 4.8.0.0

(^.) :: s -> Getting a s a -> a infixl 8

View the value pointed to by a Getter or Lens or the result of folding over all the results of a Fold or Traversal that points at a monoidal values.

This is the same operation as view with the arguments flipped.

The fixity and semantics are such that subsequent field accesses can be performed with (.).

>>> (a,b)^._2
b
>>> ("hello","world")^._2
"world"
>>> import Data.Complex
>>> ((0, 1 :+ 2), 3)^._1._2.to magnitude
2.23606797749979
(^.) ::             s -> Getter s a     -> a
(^.) :: Monoid m => s -> Fold s m       -> m
(^.) ::             s -> Iso' s a       -> a
(^.) ::             s -> Lens' s a      -> a
(^.) :: Monoid m => s -> Traversal' s m -> m

(.~) :: ASetter s t a b -> b -> s -> t infixr 4

Replace the target of a Lens or all of the targets of a Setter or Traversal with a constant value.

This is an infix version of set, provided for consistency with (.=).

f <$ a ≡ mapped .~ f $ a
>>> (a,b,c,d) & _4 .~ e
(a,b,c,e)
>>> (42,"world") & _1 .~ "hello"
("hello","world")
>>> (a,b) & both .~ c
(c,c)
(.~) :: Setter s t a b    -> b -> s -> t
(.~) :: Iso s t a b       -> b -> s -> t
(.~) :: Lens s t a b      -> b -> s -> t
(.~) :: Traversal s t a b -> b -> s -> t

type Lens' s a = Lens s s a a

type Lens' = Simple Lens

type Getter s a = forall f. (Contravariant f, Functor f) => (a -> f a) -> s -> f s

A Getter describes how to retrieve a single value in a way that can be composed with other LensLike constructions.

Unlike a Lens a Getter is read-only. Since a Getter cannot be used to write back there are no Lens laws that can be applied to it. In fact, it is isomorphic to an arbitrary function from (s -> a).

Moreover, a Getter can be used directly as a Fold, since it just ignores the Applicative.

to :: (Profunctor p, Contravariant f) => (s -> a) -> Optic' * * p f s a

Build an (index-preserving) Getter from an arbitrary Haskell function.

to f . to g ≡ to (g . f)
a ^. to f ≡ f a
>>> a ^.to f
f a
>>> ("hello","world")^.to snd
"world"
>>> 5^.to succ
6
>>> (0, -5)^._2.to abs
5
to :: (s -> a) -> IndexPreservingGetter s a

lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b

Build a Lens from a getter and a setter.

lens :: Functor f => (s -> a) -> (s -> b -> t) -> (a -> f b) -> s -> f t
>>> s ^. lens getter setter
getter s
>>> s & lens getter setter .~ b
setter s b
>>> s & lens getter setter %~ f
setter s (f (getter s))
lens :: (s -> a) -> (s -> a -> s) -> Lens' s a

when :: Applicative f => Bool -> f () -> f ()

Conditional execution of Applicative expressions. For example,

when debug (putStrLn "Debugging")

will output the string Debugging if the Boolean value debug is True, and otherwise do nothing.

unless :: Applicative f => Bool -> f () -> f ()

The reverse of when.

forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b)

forM is mapM with its arguments flipped. For a version that ignores the results see forM_.

forM_ :: (Foldable t, Monad m) => t a -> (a -> m b) -> m ()

forM_ is mapM_ with its arguments flipped. For a version that doesn't ignore the results see forM.

As of base 4.8.0.0, forM_ is just for_, specialized to Monad.

void :: Functor f => f a -> f ()

void value discards or ignores the result of evaluation, such as the return value of an IO action.

Examples

Replace the contents of a Maybe Int with unit:

>>> void Nothing
Nothing
>>> void (Just 3)
Just ()

Replace the contents of an Either Int Int with unit, resulting in an Either Int '()':

>>> void (Left 8675309)
Left 8675309
>>> void (Right 8675309)
Right ()

Replace every element of a list with unit:

>>> void [1,2,3]
[(),(),()]

Replace the second element of a pair with unit:

>>> void (1,2)
(1,())

Discard the result of an IO action:

>>> mapM print [1,2]
1
2
[(),()]
>>> void $ mapM print [1,2]
1
2

replicateM :: Monad m => Int -> m a -> m [a]

replicateM n act performs the action n times, gathering the results.

forever :: Monad m => m a -> m b

forever act repeats the action infinitely.

guard :: Alternative f => Bool -> f ()

guard b is pure () if b is True, and empty if b is False.

newtype Identity a :: * -> *

Identity functor and monad. (a non-strict monad)

Since: 4.8.0.0

Constructors

Identity 

Fields

runIdentity :: a
 

Instances

Monad Identity 
Functor Identity 
MonadFix Identity 
Applicative Identity 
Foldable Identity 
Traversable Identity 
Generic1 Identity 
MonadZip Identity 
Eq1 Identity 
Ord1 Identity 
Read1 Identity 
Show1 Identity 
Comonad Identity 
Representable Identity 
ComonadApply Identity 
MonadBaseControl Identity Identity 
Sieve ReifiedGetter Identity 
Cosieve ReifiedGetter Identity 
Eq a => Eq (Identity a) 
Data a => Data (Identity a) 
Ord a => Ord (Identity a) 
Read a => Read (Identity a)

This instance would be equivalent to the derived instances of the Identity newtype if the runIdentity field were removed

Show a => Show (Identity a)

This instance would be equivalent to the derived instances of the Identity newtype if the runIdentity field were removed

Generic (Identity a) 
NFData a => NFData (Identity a)

Since: 1.4.0.0

Semigroup a => Semigroup (Identity a) 
Ixed (Identity a) 
Wrapped (Identity a) 
(~) * t (Identity b) => Rewrapped (Identity a) t 
Field1 (Identity a) (Identity b) a b 
type Rep1 Identity = D1 D1Identity (C1 C1_0Identity (S1 S1_0_0Identity Par1)) 
type Rep Identity = () 
type StM Identity a = a 
type Rep (Identity a) = D1 D1Identity (C1 C1_0Identity (S1 S1_0_0Identity (Rec0 a))) 
type Index (Identity a) = () 
type IxValue (Identity a) = a 
type Unwrapped (Identity a) = a 

class Monad m => MonadIO m where

Monads in which IO computations may be embedded. Any monad built by applying a sequence of monad transformers to the IO monad will be an instance of this class.

Instances should satisfy the following laws, which state that liftIO is a transformer of monads:

Methods

liftIO :: IO a -> m a

Lift a computation from the IO monad.

Instances

MonadIO IO 
MonadIO m => MonadIO (MaybeT m) 
MonadIO m => MonadIO (ListT m) 
MonadIO m => MonadIO (SafeT m) 
MonadIO m => MonadIO (ListT m) 
MonadIO m => MonadIO (IdentityT m) 
MonadIO m => MonadIO (Codensity m) 
MonadIO m => MonadIO (CatchT m) 
MonadIO m => MonadIO (RandT g m) 
(Error e, MonadIO m) => MonadIO (ErrorT e m) 
(Monoid w, MonadIO m) => MonadIO (WriterT w m) 
MonadIO m => MonadIO (StateT s m) 
MonadIO m => MonadIO (ReaderT r m) 
(Functor f, MonadIO m) => MonadIO (FreeT f m) 
(Monoid w, MonadIO m) => MonadIO (WriterT w m) 
MonadIO m => MonadIO (ExceptT e m) 
MonadIO m => MonadIO (StateT s m) 
MonadIO m => MonadIO (ContT r m) 
(Monoid w, MonadIO m) => MonadIO (RWST r w s m) 
(Monoid w, MonadIO m) => MonadIO (RWST r w s m) 
MonadIO m => MonadIO (Proxy a' a b' b m) 

class Monad m => MonadRandom m where

An interface to random number generation monads.

Minimal complete definition

getRandom, getRandoms, getRandomR, getRandomRs

Methods

getRandom :: Random a => m a

Return a randomly-selected value of type a. See random for details.

getRandomR :: Random a => (a, a) -> m a

Return a randomly-selected value of type a in the range [lo,hi]. See randomR for details.

Instances

(Monad m, RandomGen g) => MonadRandom (RandT g m) 

getRandom :: MonadRandom m => forall a. Random a => m a

Return a randomly-selected value of type a. See random for details.

getRandomR :: MonadRandom m => forall a. Random a => (a, a) -> m a

Return a randomly-selected value of type a in the range [lo,hi]. See randomR for details.

type Rand g = RandT g Identity

A basic random monad.

data RandT g m a :: * -> (* -> *) -> * -> *

A monad transformer which adds a random number generator to an existing monad.

Instances

(Monad m, RandomGen g) => MonadSplit g (RandT g m) 
MonadReader r m => MonadReader r (RandT g m) 
MonadWriter w m => MonadWriter w (RandT g m) 
MonadState s m => MonadState s (RandT g m) 
MonadTrans (RandT g) 
Monad m => Monad (RandT g m) 
Functor m => Functor (RandT g m) 
MonadFix m => MonadFix (RandT g m) 
(Functor m, Monad m) => Applicative (RandT g m) 
(Monad m, RandomGen g) => MonadRandom (RandT g m) 
(Functor m, MonadPlus m) => Alternative (RandT g m) 
MonadPlus m => MonadPlus (RandT g m) 
MonadIO m => MonadIO (RandT g m) 

runRand :: Rand g a -> g -> (a, g)

Run a random computation using the generator g, returning the result and the updated generator.

evalRand :: Rand g a -> g -> a

Evaluate a random computation using the generator g. Note that the generator g is not returned, so there's no way to recover the updated version of g.

runRandT :: RandT g m a -> g -> m (a, g)

Run a RandT computation using the generator g, returning the result and the updated generator.

evalRandT :: Monad m => RandT g m a -> g -> m a

Evaluate a RandT computation using the generator g. Note that the generator g is not returned, so there's no way to recover the updated version of g.

data StdGen :: *

Instances

Read StdGen 
Show StdGen 
RandomGen StdGen 

class Monad m => MonadState s m | m -> s where

Minimal complete definition

state | get, put

Methods

get :: m s

put :: s -> m ()

state :: (s -> (a, s)) -> m a

Instances

MonadState s m => MonadState s (CatchT m) 
MonadState s m => MonadState s (SafeT m) 
MonadState s m => MonadState s (ListT m) 
MonadReader r m => MonadState r (Codensity m) 
MonadState s m => MonadState s (MaybeT m) 
MonadState s m => MonadState s (ListT m) 
MonadState s m => MonadState s (IdentityT m) 
(Functor f, MonadState s m) => MonadState s (FreeT f m) 
(Monoid w, MonadState s m) => MonadState s (WriterT w m) 
(Monoid w, MonadState s m) => MonadState s (WriterT w m) 
Monad m => MonadState s (StateT s m) 
Monad m => MonadState s (StateT s m) 
MonadState s m => MonadState s (ReaderT r m) 
MonadState s m => MonadState s (ExceptT e m) 
(Error e, MonadState s m) => MonadState s (ErrorT e m) 
MonadState s m => MonadState s (ContT r m) 
MonadState s m => MonadState s (RandT g m) 
(Monad m, Monoid w) => MonadState s (RWST r w s m) 
(Monad m, Monoid w) => MonadState s (RWST r w s m) 
MonadState s m => MonadState s (Proxy a' a b' b m) 

lift :: MonadTrans t => forall m a. Monad m => m a -> t m a

Lift a computation from the argument monad to the constructed monad.

type State s = StateT s Identity

A state monad parameterized by the type s of the state to carry.

The return function leaves the state unchanged, while >>= uses the final state of the first computation as the initial state of the second.

data StateT s m a :: * -> (* -> *) -> * -> *

A state transformer monad parameterized by:

  • s - The state.
  • m - The inner monad.

The return function leaves the state unchanged, while >>= uses the final state of the first computation as the initial state of the second.

Instances

MonadReader r m => MonadReader r (StateT s m) 
Monad m => MonadState s (StateT s m) 
MonadBaseControl b m => MonadBaseControl b (StateT s m) 
MonadTrans (StateT s) 
MonadTransControl (StateT s) 
Monad m => Monad (StateT s m) 
Functor m => Functor (StateT s m) 
MonadFix m => MonadFix (StateT s m) 
(Functor m, Monad m) => Applicative (StateT s m) 
(Functor m, MonadPlus m) => Alternative (StateT s m) 
MonadPlus m => MonadPlus (StateT s m) 
MonadIO m => MonadIO (StateT s m) 
MonadThrow m => MonadThrow (StateT s m) 
MonadCatch m => MonadCatch (StateT s m) 
Contravariant m => Contravariant (StateT s m) 
MonadMask m => MonadMask (StateT s m) 
MonadSafe m => MonadSafe (StateT s m) 
PrimMonad m => PrimMonad (StateT s m) 
Monad z => Zoom (StateT s z) (StateT t z) s t 
Wrapped (StateT s m a) 
(~) * t (StateT s' m' a') => Rewrapped (StateT s m a) t 
type StT (StateT s) a = (a, s) 
type Zoomed (StateT s z) = Focusing z 
type Base (StateT s m) = Base m 
type PrimState (StateT s m) = PrimState m 
type StM (StateT s m) a = ComposeSt (StateT s) m a 
type Unwrapped (StateT s m a) = s -> m (a, s) 

modify :: Monad m => (s -> s) -> StateT s m ()

modify f is an action that updates the state to the result of applying f to the current state.

runState

Arguments

:: State s a

state-passing computation to execute

-> s

initial state

-> (a, s)

return value and final state

Unwrap a state monad computation as a function. (The inverse of state.)

evalState

Arguments

:: State s a

state-passing computation to execute

-> s

initial value

-> a

return value of the state computation

Evaluate a state computation with the given initial state and return the final value, discarding the final state.

execState

Arguments

:: State s a

state-passing computation to execute

-> s

initial value

-> s

final state

Evaluate a state computation with the given initial state and return the final state, discarding the final value.

runStateT :: StateT s m a -> s -> m (a, s)

evalStateT :: Monad m => StateT s m a -> s -> m a

Evaluate a state computation with the given initial state and return the final value, discarding the final state.

execStateT :: Monad m => StateT s m a -> s -> m s

Evaluate a state computation with the given initial state and return the final state, discarding the final value.

type Writer w = WriterT w Identity

A writer monad parameterized by the type w of output to accumulate.

The return function produces the output mempty, while >>= combines the outputs of the subcomputations using mappend.

data WriterT w m a :: * -> (* -> *) -> * -> *

A writer monad parameterized by:

  • w - the output to accumulate.
  • m - The inner monad.

The return function produces the output mempty, while >>= combines the outputs of the subcomputations using mappend.

Instances

(Monoid w, MonadReader r m) => MonadReader r (WriterT w m) 
(Monoid w, MonadState s m) => MonadState s (WriterT w m) 
(Monoid w, MonadBaseControl b m) => MonadBaseControl b (WriterT w m) 
Monoid w => MonadTrans (WriterT w) 
Monoid w => MonadTransControl (WriterT w) 
(Monoid w, Monad m) => Monad (WriterT w m) 
Functor m => Functor (WriterT w m) 
(Monoid w, MonadFix m) => MonadFix (WriterT w m) 
(Monoid w, Applicative m) => Applicative (WriterT w m) 
Foldable f => Foldable (WriterT w f) 
Traversable f => Traversable (WriterT w f) 
(Monoid w, Alternative m) => Alternative (WriterT w m) 
(Monoid w, MonadPlus m) => MonadPlus (WriterT w m) 
(Monoid w, MonadIO m) => MonadIO (WriterT w m) 
(MonadThrow m, Monoid w) => MonadThrow (WriterT w m) 
(MonadCatch m, Monoid w) => MonadCatch (WriterT w m) 
Contravariant m => Contravariant (WriterT w m) 
(MonadMask m, Monoid w) => MonadMask (WriterT w m) 
(MonadSafe m, Monoid w) => MonadSafe (WriterT w m) 
(Eq w, Eq1 m) => Eq1 (WriterT w m) 
(Ord w, Ord1 m) => Ord1 (WriterT w m) 
(Read w, Read1 m) => Read1 (WriterT w m) 
(Show w, Show1 m) => Show1 (WriterT w m) 
(Monoid w, PrimMonad m) => PrimMonad (WriterT w m) 
(Monoid w, Zoom m n s t) => Zoom (WriterT w m) (WriterT w n) s t 
(Eq w, Eq1 m, Eq a) => Eq (WriterT w m a) 
(Ord w, Ord1 m, Ord a) => Ord (WriterT w m a) 
(Read w, Read1 m, Read a) => Read (WriterT w m a) 
(Show w, Show1 m, Show a) => Show (WriterT w m a) 
Wrapped (WriterT w m a) 
(~) * t (WriterT w' m' a') => Rewrapped (WriterT w m a) t 
type StT (WriterT w) a = (a, w) 
type Zoomed (WriterT w m) = FocusingPlus w (Zoomed m) 
type Base (WriterT w m) = Base m 
type PrimState (WriterT w m) = PrimState m 
type StM (WriterT w m) a = ComposeSt (WriterT w) m a 
type Unwrapped (WriterT w m a) = m (a, w) 

tell :: (Monoid w, Monad m) => w -> WriterT w m ()

tell w is an action that produces the output w.

runWriter :: Writer w a -> (a, w)

Unwrap a writer computation as a (result, output) pair. (The inverse of writer.)

execWriter :: Writer w a -> w

Extract the output from a writer computation.

runWriterT :: WriterT w m a -> m (a, w)

execWriterT :: Monad m => WriterT w m a -> m w

Extract the output from a writer computation.

lefts :: [Either a b] -> [a]

Extracts from a list of Either all the Left elements. All the Left elements are extracted in order.

Examples

Basic usage:

>>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ]
>>> lefts list
["foo","bar","baz"]

rights :: [Either a b] -> [b]

Extracts from a list of Either all the Right elements. All the Right elements are extracted in order.

Examples

Basic usage:

>>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ]
>>> rights list
[3,7]

toList :: Foldable t => forall a. t a -> [a]

List of elements of a structure, from left to right.

on :: (b -> b -> c) -> (a -> b) -> a -> a -> c infixl 0

(*) `on` f = \x y -> f x * f y.

Typical usage: sortBy (compare `on` fst).

Algebraic properties:

  • (*) `on` id = (*) (if (*) ∉ {⊥, const ⊥})
  • ((*) `on` f) `on` g = (*) `on` (f . g)
  • flip on f . flip on g = flip on (g . f)

sort :: Ord a => [a] -> [a]

The sort function implements a stable sorting algorithm. It is a special case of sortBy, which allows the programmer to supply their own comparison function.

sortBy :: (a -> a -> Ordering) -> [a] -> [a]

The sortBy function is the non-overloaded version of sort.

minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a

The least element of a non-empty structure with respect to the given comparison function.

maximumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a

The largest element of a non-empty structure with respect to the given comparison function.

foldl' :: Foldable t => forall b a. (b -> a -> b) -> b -> t a -> b

Left-associative fold of a structure. but with strict application of the operator.

foldl f z = foldl' f z . toList

intercalate :: [a] -> [[a]] -> [a]

intercalate xs xss is equivalent to (concat (intersperse xs xss)). It inserts the list xs in between the lists in xss and concatenates the result.

catMaybes :: [Maybe a] -> [a]

The catMaybes function takes a list of Maybes and returns a list of all the Just values.

Examples

Basic usage:

>>> catMaybes [Just 1, Nothing, Just 3]
[1,3]

When constructing a list of Maybe values, catMaybes can be used to return all of the "success" results (if the list is the result of a map, then mapMaybe would be more appropriate):

>>> import Text.Read ( readMaybe )
>>> [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ]
[Just 1,Nothing,Just 3]
>>> catMaybes $ [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ]
[1,3]

fromJust :: Maybe a -> a

The fromJust function extracts the element out of a Just and throws an error if its argument is Nothing.

Examples

Basic usage:

>>> fromJust (Just 1)
1
>>> 2 * (fromJust (Just 10))
20
>>> 2 * (fromJust Nothing)
*** Exception: Maybe.fromJust: Nothing

fromMaybe :: a -> Maybe a -> a

The fromMaybe function takes a default value and and Maybe value. If the Maybe is Nothing, it returns the default values; otherwise, it returns the value contained in the Maybe.

Examples

Basic usage:

>>> fromMaybe "" (Just "Hello, World!")
"Hello, World!"
>>> fromMaybe "" Nothing
""

Read an integer from a string using readMaybe. If we fail to parse an integer, we want to return 0 by default:

>>> import Text.Read ( readMaybe )
>>> fromMaybe 0 (readMaybe "5")
5
>>> fromMaybe 0 (readMaybe "")
0

(<>) :: Monoid m => m -> m -> m infixr 6

An infix synonym for mappend.

Since: 4.5.0.0

getDirectoryContents :: FilePath -> IO [FilePath]

getDirectoryContents dir returns a list of all entries in dir.

The operation may fail with:

  • HardwareFault A physical I/O error has occurred. [EIO]
  • InvalidArgument The operand is not a valid directory name. [ENAMETOOLONG, ELOOP]
  • isDoesNotExistError / NoSuchThing The directory does not exist. [ENOENT, ENOTDIR]
  • isPermissionError / PermissionDenied The process has insufficient privileges to perform the operation. [EACCES]
  • ResourceExhausted Insufficient resources are available to perform the operation. [EMFILE, ENFILE]
  • InappropriateType The path refers to an existing non-directory object. [ENOTDIR]

getArgs :: IO [String]

Computation getArgs returns a list of the program's command line arguments (not including the program name).

(</>) :: FilePath -> FilePath -> FilePath infixr 5

Join two values with a path separator. For examples and caveats see the equivalent function combine.

Posix:   "/directory" </> "file.ext" == "/directory/file.ext"
Windows: "/directory" </> "file.ext" == "/directory\\file.ext"

(<.>) :: FilePath -> String -> FilePath infixr 7

Add an extension, even if there is already one there, equivalent to addExtension.

"/directory/path" <.> "ext" == "/directory/path.ext"
"/directory/path" <.> ".ext" == "/directory/path.ext"

withFile :: FilePath -> IOMode -> (Handle -> IO r) -> IO r

withFile name mode act opens a file using openFile and passes the resulting handle to the computation act. The handle will be closed on exit from withFile, whether by normal termination or by raising an exception. If closing the handle raises an exception, then this exception will be raised by withFile rather than any exception raised by act.

hPutStr :: Handle -> String -> IO ()

Computation hPutStr hdl s writes the string s to the file or channel managed by hdl.

This operation may fail with:

hPutStrLn :: Handle -> String -> IO ()

The same as hPutStr, but adds a newline character.

printf :: PrintfType r => String -> r

Format a variable number of arguments with the C-style formatting string. The return value is either String or (IO a) (which should be (IO '()'), but Haskell's type system makes this hard).

The format string consists of ordinary characters and conversion specifications, which specify how to format one of the arguments to printf in the output string. A format specification is introduced by the % character; this character can be self-escaped into the format string using %%. A format specification ends with a /format character/ that provides the primary information about how to format the value. The rest of the conversion specification is optional. In order, one may have flag characters, a width specifier, a precision specifier, and type-specific modifier characters.

Unlike C printf(3), the formatting of this printf is driven by the argument type; formatting is type specific. The types formatted by printf "out of the box" are:

printf is also extensible to support other types: see below.

A conversion specification begins with the character %, followed by zero or more of the following flags:

   -      left adjust (default is right adjust)
   +      always use a sign (+ or -) for signed conversions
   space  leading space for positive numbers in signed conversions
   0      pad with zeros rather than spaces
   #      use an \"alternate form\": see below

When both flags are given, - overrides 0 and + overrides space. A negative width specifier in a * conversion is treated as positive but implies the left adjust flag.

The "alternate form" for unsigned radix conversions is as in C printf(3):

   %o           prefix with a leading 0 if needed
   %x           prefix with a leading 0x if nonzero
   %X           prefix with a leading 0X if nonzero
   %b           prefix with a leading 0b if nonzero
   %[eEfFgG]    ensure that the number contains a decimal point

Any flags are followed optionally by a field width:

   num    field width
   *      as num, but taken from argument list

The field width is a minimum, not a maximum: it will be expanded as needed to avoid mutilating a value.

Any field width is followed optionally by a precision:

   .num   precision
   .      same as .0
   .*     as num, but taken from argument list

Negative precision is taken as 0. The meaning of the precision depends on the conversion type.

   Integral    minimum number of digits to show
   RealFloat   number of digits after the decimal point
   String      maximum number of characters

The precision for Integral types is accomplished by zero-padding. If both precision and zero-pad are given for an Integral field, the zero-pad is ignored.

Any precision is followed optionally for Integral types by a width modifier; the only use of this modifier being to set the implicit size of the operand for conversion of a negative operand to unsigned:

   hh     Int8
   h      Int16
   l      Int32
   ll     Int64
   L      Int64

The specification ends with a format character:

   c      character               Integral
   d      decimal                 Integral
   o      octal                   Integral
   x      hexadecimal             Integral
   X      hexadecimal             Integral
   b      binary                  Integral
   u      unsigned decimal        Integral
   f      floating point          RealFloat
   F      floating point          RealFloat
   g      general format float    RealFloat
   G      general format float    RealFloat
   e      exponent format float   RealFloat
   E      exponent format float   RealFloat
   s      string                  String
   v      default format          any type

The "%v" specifier is provided for all built-in types, and should be provided for user-defined type formatters as well. It picks a "best" representation for the given type. For the built-in types the "%v" specifier is converted as follows:

   c      Char
   u      other unsigned Integral
   d      other signed Integral
   g      RealFloat
   s      String

Mismatch between the argument types and the format string, as well as any other syntactic or semantic errors in the format string, will cause an exception to be thrown at runtime.

Note that the formatting for RealFloat types is currently a bit different from that of C printf(3), conforming instead to showEFloat, showFFloat and showGFloat (and their alternate versions showFFloatAlt and showGFloatAlt). This is hard to fix: the fixed versions would format in a backward-incompatible way. In any case the Haskell behavior is generally more sensible than the C behavior. A brief summary of some key differences:

  • Haskell printf never uses the default "6-digit" precision used by C printf.
  • Haskell printf treats the "precision" specifier as indicating the number of digits after the decimal point.
  • Haskell printf prints the exponent of e-format numbers without a gratuitous plus sign, and with the minimum possible number of digits.
  • Haskell printf will place a zero after a decimal point when possible.

Examples

  > printf "%d\n" (23::Int)
  23
  > printf "%s %s\n" "Hello" "World"
  Hello World
  > printf "%.2f\n" pi
  3.14