| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Yam.Import
- data Text :: *
- pack :: String -> Text
- cs :: ConvertibleStrings a b => a -> b
- showText :: Show a => a -> Text
- lift :: MonadTrans t => forall (m :: * -> *) a. Monad m => m a -> t m a
- class Monad m => MonadIO (m :: * -> *) where
- liftIO :: MonadIO m => forall a. IO a -> m a
- when :: Applicative f => Bool -> f () -> f ()
- unless :: Applicative f => Bool -> f () -> f ()
- void :: Functor f => f a -> f ()
- (<>) :: Monoid m => m -> m -> m
- myThreadId :: IO ThreadId
- data ThreadId :: *
- killThread :: ThreadId -> IO ()
- fromMaybe :: a -> Maybe a -> a
- maybe :: b -> (a -> b) -> Maybe a -> b
- mapMaybe :: (a -> Maybe b) -> [a] -> [b]
- catMaybes :: [Maybe a] -> [a]
- selectMaybe :: [Maybe a] -> Maybe a
- finally :: MonadMask m => m a -> m b -> m a
- class MonadCatch m => MonadMask (m :: * -> *)
- class Monad m => MonadThrow (m :: * -> *)
- class MonadThrow m => MonadCatch (m :: * -> *)
- catchAll :: MonadCatch m => m a -> (SomeException -> m a) -> m a
- runReaderT :: ReaderT k r m a -> r -> m a
- data ReaderT k r (m :: k -> *) (a :: k) :: forall k. * -> (k -> *) -> k -> *
- ask :: Monad m => ReaderT * r m r
- class Generic a
- data UTCTime :: *
- randomHex :: Int -> IO Text
- data Proxy k (t :: k) :: forall k. k -> * = Proxy
Documentation
A space efficient, packed, unboxed Unicode text type.
Instances
cs :: ConvertibleStrings a b => a -> b #
lift :: MonadTrans t => forall (m :: * -> *) a. Monad m => m a -> t m a #
Lift a computation from the argument monad to the constructed monad.
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:
Minimal complete definition
Instances
| MonadIO IO | Since: 4.9.0.0 |
| MonadIO m => MonadIO (MaybeT m) | |
| MonadIO m => MonadIO (ListT m) | |
| MonadIO m => MonadIO (NoLoggingT m) | |
| MonadIO m => MonadIO (LoggingT m) | |
| MonadIO m => MonadIO (ResourceT m) | |
| (Monoid w, MonadIO m) => MonadIO (WriterT w m) | |
| (Monoid w, MonadIO m) => MonadIO (WriterT w m) | |
| MonadIO m => MonadIO (StateT s m) | |
| MonadIO m => MonadIO (StateT s m) | |
| (Error e, MonadIO m) => MonadIO (ErrorT e m) | |
| MonadIO m => MonadIO (ExceptT e m) | |
| MonadIO m => MonadIO (IdentityT * m) | |
| MonadIO m => MonadIO (ReaderT * r m) | |
| MonadIO m => MonadIO (ConduitM i o 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 (Pipe l i o u m) | |
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.
void :: Functor f => f a -> f () #
discards or ignores the result of evaluation, such
as the return value of an void valueIO action.
Examples
Replace the contents of a with unit:Maybe Int
>>>void NothingNothing>>>void (Just 3)Just ()
Replace the contents of an with unit,
resulting in an Either Int Int: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
myThreadId :: IO ThreadId #
Returns the ThreadId of the calling thread (GHC only).
A ThreadId is an abstract type representing a handle to a thread.
ThreadId is an instance of Eq, Ord and Show, where
the Ord instance implements an arbitrary total ordering over
ThreadIds. The Show instance lets you convert an arbitrary-valued
ThreadId to string form; showing a ThreadId value is occasionally
useful when debugging or diagnosing the behaviour of a concurrent
program.
Note: in GHC, if you have a ThreadId, you essentially have
a pointer to the thread itself. This means the thread itself can't be
garbage collected until you drop the ThreadId.
This misfeature will hopefully be corrected at a later date.
killThread :: ThreadId -> IO () #
killThread raises the ThreadKilled exception in the given
thread (GHC only).
killThread tid = throwTo tid ThreadKilled
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
maybe :: b -> (a -> b) -> Maybe a -> b #
The maybe function takes a default value, a function, and a Maybe
value. If the Maybe value is Nothing, the function returns the
default value. Otherwise, it applies the function to the value inside
the Just and returns the result.
Examples
Basic usage:
>>>maybe False odd (Just 3)True
>>>maybe False odd NothingFalse
Read an integer from a string using readMaybe. If we succeed,
return twice the integer; that is, apply (*2) to it. If instead
we fail to parse an integer, return 0 by default:
>>>import Text.Read ( readMaybe )>>>maybe 0 (*2) (readMaybe "5")10>>>maybe 0 (*2) (readMaybe "")0
Apply show to a Maybe Int. If we have Just n, we want to show
the underlying Int n. But if we have Nothing, we return the
empty string instead of (for example) "Nothing":
>>>maybe "" show (Just 5)"5">>>maybe "" show Nothing""
mapMaybe :: (a -> Maybe b) -> [a] -> [b] #
The mapMaybe function is a version of map which can throw
out elements. In particular, the functional argument returns
something of type . If this is Maybe bNothing, no element
is added on to the result list. If it is , then Just bb is
included in the result list.
Examples
Using is a shortcut for mapMaybe f x
in most cases:catMaybes $ map f x
>>>import Text.Read ( readMaybe )>>>let readMaybeInt = readMaybe :: String -> Maybe Int>>>mapMaybe readMaybeInt ["1", "Foo", "3"][1,3]>>>catMaybes $ map readMaybeInt ["1", "Foo", "3"][1,3]
If we map the Just constructor, the entire list should be returned:
>>>mapMaybe Just [1,2,3][1,2,3]
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]
selectMaybe :: [Maybe a] -> Maybe a Source #
finally :: MonadMask m => m a -> m b -> m a #
Perform an action with a finalizer action that is run, even if an exception occurs.
class MonadCatch m => MonadMask (m :: * -> *) #
A class for monads which provide for the ability to account for all
possible exit points from a computation, and to mask asynchronous
exceptions. Continuation-based monads, and stacks such as ErrorT e IO
which provide for multiple failure modes, are invalid instances of this
class.
Note that this package does provide a MonadMask instance for CatchT.
This instance is only valid if the base monad provides no ability to
provide multiple exit. For example, IO or Either would be invalid base
monads, but Reader or State would be acceptable.
Instances should ensure that, in the following code:
f `finally` g
The action g is called regardless of what occurs within f, including
async exceptions.
Minimal complete definition
Instances
| MonadMask IO | |
| (~) * e SomeException => MonadMask (Either e) | Since: 0.8.3 |
| MonadMask m => MonadMask (NoLoggingT m) | |
| MonadMask m => MonadMask (LoggingT m) | |
| MonadMask m => MonadMask (ResourceT m) | |
| (MonadMask m, Monoid w) => MonadMask (WriterT w m) | |
| (MonadMask m, Monoid w) => MonadMask (WriterT w m) | |
| MonadMask m => MonadMask (StateT s m) | |
| MonadMask m => MonadMask (StateT s m) | |
| MonadMask m => MonadMask (IdentityT * m) | |
| MonadMask m => MonadMask (ReaderT * r m) | |
| (MonadMask m, Monoid w) => MonadMask (RWST r w s m) | |
| (MonadMask m, Monoid w) => MonadMask (RWST r w s m) | |
class Monad m => MonadThrow (m :: * -> *) #
A class for monads in which exceptions may be thrown.
Instances should obey the following law:
throwM e >> x = throwM e
In other words, throwing an exception short-circuits the rest of the monadic computation.
Minimal complete definition
Instances
class MonadThrow m => MonadCatch (m :: * -> *) #
A class for monads which allow exceptions to be caught, in particular
exceptions which were thrown by throwM.
Instances should obey the following law:
catch (throwM e) f = f e
Note that the ability to catch an exception does not guarantee that we can
deal with all possible exit points from a computation. Some monads, such as
continuation-based stacks, allow for more than just a success/failure
strategy, and therefore catch cannot be used by those monads to properly
implement a function such as finally. For more information, see
MonadMask.
Minimal complete definition
Instances
| MonadCatch IO | |
| MonadCatch STM | |
| (~) * e SomeException => MonadCatch (Either e) | Since: 0.8.3 |
| MonadCatch m => MonadCatch (MaybeT m) | Catches exceptions from the base monad. |
| MonadCatch m => MonadCatch (ListT m) | |
| MonadCatch m => MonadCatch (NoLoggingT m) | |
| MonadCatch m => MonadCatch (LoggingT m) | |
| MonadCatch m => MonadCatch (ResourceT m) | |
| (MonadCatch m, Monoid w) => MonadCatch (WriterT w m) | |
| (MonadCatch m, Monoid w) => MonadCatch (WriterT w m) | |
| MonadCatch m => MonadCatch (StateT s m) | |
| MonadCatch m => MonadCatch (StateT s m) | |
| (Error e, MonadCatch m) => MonadCatch (ErrorT e m) | Catches exceptions from the base monad. |
| MonadCatch m => MonadCatch (ExceptT e m) | Catches exceptions from the base monad. |
| MonadCatch m => MonadCatch (IdentityT * m) | |
| MonadCatch m => MonadCatch (ReaderT * r m) | |
| MonadCatch m => MonadCatch (ConduitM i o m) | |
| (MonadCatch m, Monoid w) => MonadCatch (RWST r w s m) | |
| (MonadCatch m, Monoid w) => MonadCatch (RWST r w s m) | |
| MonadCatch m => MonadCatch (Pipe l i o u m) | |
catchAll :: MonadCatch m => m a -> (SomeException -> m a) -> m a #
Catches all exceptions, and somewhat defeats the purpose of the extensible exception system. Use sparingly.
runReaderT :: ReaderT k r m a -> r -> m a #
data ReaderT k r (m :: k -> *) (a :: k) :: forall k. * -> (k -> *) -> k -> * #
The reader monad transformer, which adds a read-only environment to the given monad.
The return function ignores the environment, while >>= passes
the inherited environment to both subcomputations.
Instances
| MonadBaseControl b m => MonadBaseControl b (ReaderT * r m) | |
| MonadBase b m => MonadBase b (ReaderT * r m) | |
| MonadTrans (ReaderT * r) | |
| MonadTransControl (ReaderT * r) | |
| Monad m => Monad (ReaderT * r m) | |
| Functor m => Functor (ReaderT * r m) | |
| MonadFix m => MonadFix (ReaderT * r m) | |
| MonadFail m => MonadFail (ReaderT * r m) | |
| Applicative m => Applicative (ReaderT * r m) | |
| Alternative m => Alternative (ReaderT * r m) | |
| MonadPlus m => MonadPlus (ReaderT * r m) | |
| MonadZip m => MonadZip (ReaderT * r m) | |
| MonadIO m => MonadIO (ReaderT * r m) | |
| MonadThrow m => MonadThrow (ReaderT * r m) | |
| MonadCatch m => MonadCatch (ReaderT * r m) | |
| MonadMask m => MonadMask (ReaderT * r m) | |
| MonadLogger m => MonadLogger (ReaderT * r m) | |
| MonadLoggerIO m => MonadLoggerIO (ReaderT * r m) | |
| PrimMonad m => PrimMonad (ReaderT * r m) | |
| MonadResource m => MonadResource (ReaderT * r m) | |
| MonadIO m => MonadLogger (ReaderT * LoggerConfig m) Source # | |
| type StT (ReaderT * r) a | |
| type PrimState (ReaderT * r m) | |
| type StM (ReaderT * r m) a | |
Representable types of kind *. This class is derivable in GHC with the DeriveGeneric flag on.
Instances
This is the simplest representation of UTC. It consists of the day number, and a time offset from midnight. Note that if a day has a leap second added to it, it will have 86401 seconds.
data Proxy k (t :: k) :: forall k. k -> * #
A concrete, poly-kinded proxy type
Constructors
| Proxy |
Instances
| Generic1 k (Proxy k) | |
| Monad (Proxy *) | Since: 4.7.0.0 |
| Functor (Proxy *) | Since: 4.7.0.0 |
| Applicative (Proxy *) | Since: 4.7.0.0 |
| Foldable (Proxy *) | Since: 4.7.0.0 |
| Traversable (Proxy *) | Since: 4.7.0.0 |
| ToJSON1 (Proxy *) | |
| FromJSON1 (Proxy *) | |
| Alternative (Proxy *) | Since: 4.9.0.0 |
| MonadPlus (Proxy *) | Since: 4.9.0.0 |
| Eq1 (Proxy *) | Since: 4.9.0.0 |
| Ord1 (Proxy *) | Since: 4.9.0.0 |
| Read1 (Proxy *) | Since: 4.9.0.0 |
| Show1 (Proxy *) | Since: 4.9.0.0 |
| Hashable1 (Proxy *) | |
| Bounded (Proxy k t) | |
| Enum (Proxy k s) | Since: 4.7.0.0 |
| Eq (Proxy k s) | Since: 4.7.0.0 |
| Ord (Proxy k s) | Since: 4.7.0.0 |
| Read (Proxy k s) | Since: 4.7.0.0 |
| Show (Proxy k s) | Since: 4.7.0.0 |
| Ix (Proxy k s) | Since: 4.7.0.0 |
| Generic (Proxy k t) | |
| Semigroup (Proxy k s) | Since: 4.9.0.0 |
| Monoid (Proxy k s) | Since: 4.7.0.0 |
| Hashable (Proxy k a) | |
| ToJSON (Proxy k a) | |
| FromJSON (Proxy k a) | |
| type Rep1 k (Proxy k) | |
| type Rep (Proxy k t) | |