marvin-0.2.5: A framework for modular, portable chat bots.

Marvin.Prelude

Description

Synopsis

module Marvin

## 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

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:

• liftIO . return = return
• liftIO (m >>= f) = liftIO m >>= (liftIO . f)

Minimal complete definition

liftIO

Methods

liftIO :: IO a -> m a #

Lift a computation from the IO monad.

Instances

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