Copyright | (c) Justus Adam 2016 |
---|---|
License | BSD3 |
Maintainer | dev@justus.science |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
- module Marvin
- module Marvin.Util.Mutable
- module Marvin.Util.Logging
- module Marvin.Util.Random
- module Marvin.Util.Regex
- module Marvin.Util.JSON
- module Text.Printf
- 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 ()
- for :: (Traversable t, Applicative f) => t a -> (a -> f b) -> f (t b)
- for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f ()
- fromMaybe :: a -> Maybe a -> a
Documentation
Common functions and Types for scripts
module Marvin
Mutable references in marvin scripts
module Marvin.Util.Mutable
Logging in Scripts
module Marvin.Util.Logging
Random numbers and convenience functions
module Marvin.Util.Random
Marvins regex type and how to work with it
module Marvin.Util.Regex
Dealing with JSON
module Marvin.Util.JSON
Format strings which resolve to efficient Strings, aka Text
module Text.Printf
Arbitrary IO in scripts
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:
MonadIO IO | |
MonadIO m => MonadIO (ListT m) | |
MonadIO m => MonadIO (MaybeT m) | |
MonadIO (ScriptDefinition a) # | |
MonadIO m => MonadIO (IdentityT * m) | |
(Functor f, MonadIO m) => MonadIO (FreeT f m) | |
(Error e, MonadIO m) => MonadIO (ErrorT e m) | |
MonadIO m => MonadIO (ExceptT e m) | |
MonadIO m => MonadIO (StateT s m) | |
MonadIO m => MonadIO (StateT s m) | |
(Monoid w, MonadIO m) => MonadIO (WriterT w m) | |
(Monoid w, MonadIO m) => MonadIO (WriterT w m) | |
MonadIO (BotReacting a d) # | |
MonadIO m => MonadIO (ContT * r m) | |
MonadIO m => MonadIO (ReaderT * r m) | |
(Monoid w, MonadIO m) => MonadIO (RWST r w s m) | |
(Monoid w, MonadIO m) => MonadIO (RWST r w s m) | |
Useful functions not in the normal Prelude
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
.
for :: (Traversable t, Applicative f) => t a -> (a -> f b) -> f (t b) #
for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f () #
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