marvin-0.1.5: A modular chat bot

Copyright(c) Justus Adam 2016
LicenseBSD3
Maintainerdev@justus.science
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Marvin.Prelude

Contents

Description

 

Synopsis

Common functions and Types for scripts

module Marvin

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

isL :: String -> Q Exp #

interpolate splice to Lazy Text

Template Haskell splice function, used like $(isL "my str #{expr}")

converts all expressions to Text by calling showL on the result.

isT :: String -> Q Exp #

interpolate splice to Text

Template Haskell splice function, used like $(isT "my str #{expr}")

converts all expressions to Text by calling showT on the result.

isS :: String -> Q Exp #

interpolate splice to String

Template Haskell splice function, used like $(isS "my str #{expr}")

converts all expressions to String by calling showStr on the result.

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:

Minimal complete definition

liftIO

Methods

liftIO :: IO a -> m a #

Lift a computation from the IO monad.

Instances

MonadIO IO 

Methods

liftIO :: IO a -> IO a #

MonadIO m => MonadIO (MaybeT m) 

Methods

liftIO :: IO a -> MaybeT m a #

MonadIO m => MonadIO (InputT m) 

Methods

liftIO :: IO a -> InputT m a #

MonadIO m => MonadIO (NoLoggingT m) 

Methods

liftIO :: IO a -> NoLoggingT m a #

MonadIO m => MonadIO (LoggingT m) 

Methods

liftIO :: IO a -> LoggingT m a #

MonadIO m => MonadIO (ListT m) 

Methods

liftIO :: IO a -> ListT m a #

MonadIO m => MonadIO (ResourceT m) 

Methods

liftIO :: IO a -> ResourceT m a #

MonadIO (AdapterM a) # 

Methods

liftIO :: IO a -> AdapterM a a #

MonadIO (ScriptDefinition a) # 

Methods

liftIO :: IO a -> ScriptDefinition a a #

MonadIO m => MonadIO (IdentityT * m) 

Methods

liftIO :: IO a -> IdentityT * m a #

(Monoid w, MonadIO m) => MonadIO (WriterT w m) 

Methods

liftIO :: IO a -> WriterT w m a #

(Monoid w, MonadIO m) => MonadIO (WriterT w m) 

Methods

liftIO :: IO a -> WriterT w m a #

MonadIO m => MonadIO (StateT s m) 

Methods

liftIO :: IO a -> StateT s m a #

MonadIO m => MonadIO (StateT s m) 

Methods

liftIO :: IO a -> StateT s m a #

(Error e, MonadIO m) => MonadIO (ErrorT e m) 

Methods

liftIO :: IO a -> ErrorT e m a #

(Functor f, MonadIO m) => MonadIO (FreeT f m) 

Methods

liftIO :: IO a -> FreeT f m a #

MonadIO m => MonadIO (ExceptT e m) 

Methods

liftIO :: IO a -> ExceptT e m a #

MonadIO (BotReacting a d) # 

Methods

liftIO :: IO a -> BotReacting a d a #

MonadIO m => MonadIO (ReaderT * r m) 

Methods

liftIO :: IO a -> ReaderT * r m a #

MonadIO m => MonadIO (ConduitM i o m) 

Methods

liftIO :: IO a -> ConduitM i o m a #

MonadIO m => MonadIO (ContT * r m) 

Methods

liftIO :: IO a -> ContT * r m a #

(Monoid w, MonadIO m) => MonadIO (RWST r w s m) 

Methods

liftIO :: IO a -> RWST r w s m a #

(Monoid w, MonadIO m) => MonadIO (RWST r w s m) 

Methods

liftIO :: IO a -> RWST r w s m a #

MonadIO m => MonadIO (Pipe l i o u m) 

Methods

liftIO :: IO a -> Pipe l i o u m a #

liftIO :: MonadIO m => forall a. IO a -> m a #

Lift a computation from the IO monad.

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 is traverse with its arguments flipped. For a version that ignores the results see for_.

for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f () #

for_ is traverse_ with its arguments flipped. For a version that doesn't ignore the results see for.

>>> for_ [1..4] print
1
2
3
4

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