Copyright | (c) Justus Adam 2016 |
---|---|
License | BSD3 |
Maintainer | dev@justus.science |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
- Common functions and Types for scripts
- Mutable references in marvin scripts
- Logging in Scripts
- Random numbers and convenience functions
- Marvins regex type and how to work with it
- Dealing with JSON
- Interpolated strings a la Scala and CoffeeScript
- Arbitrary IO in scripts
- Useful functions not in the normal Prelude
- module Marvin
- module Marvin.Util.Mutable
- module Control.Monad.Logger
- module Marvin.Util.Random
- module Marvin.Util.Regex
- module Marvin.Util.JSON
- isL :: String -> Q Exp
- isT :: String -> Q Exp
- isS :: String -> Q Exp
- 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
Common functions and Types for scripts
module Marvin
Mutable references in marvin scripts
module Marvin.Util.Mutable
Logging in Scripts
module Control.Monad.Logger
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
Interpolated strings a la Scala and CoffeeScript
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 (MaybeT m) | |
MonadIO m => MonadIO (InputT m) | |
MonadIO m => MonadIO (NoLoggingT m) | |
MonadIO m => MonadIO (LoggingT m) | |
MonadIO m => MonadIO (ListT m) | |
MonadIO m => MonadIO (ResourceT m) | |
MonadIO (AdapterM a) # | |
MonadIO (ScriptDefinition a) # | |
MonadIO m => MonadIO (IdentityT * 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) | |
(Functor f, MonadIO m) => MonadIO (FreeT f m) | |
MonadIO m => MonadIO (ExceptT e m) | |
MonadIO (BotReacting a d) # | |
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) | |
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