ghc-7.8.2: The GHC API

Safe Haskell | None
Language | Haskell98

Vectorise.Monad.Base

Contents

- The Vectorisation Monad
- Lifting
- Error Handling
- Debugging
- Control

Description

The Vectorisation monad.

Synopsis

- data VResult a
  - = Yes GlobalEnv LocalEnv a
  - | No SDoc
- newtype VM a = VM {
  - runVM :: Builtins -> GlobalEnv -> LocalEnv -> DsM (VResult a)
  }
- liftDs :: DsM a -> VM a
- cantVectorise :: DynFlags -> String -> SDoc -> a
- maybeCantVectorise :: DynFlags -> String -> SDoc -> Maybe a -> a
- maybeCantVectoriseM :: (Monad m, HasDynFlags m) => String -> SDoc -> m (Maybe a) -> m a
- emitVt :: String -> SDoc -> VM ()
- traceVt :: String -> SDoc -> VM ()
- dumpOptVt :: DumpFlag -> String -> SDoc -> VM ()
- dumpVt :: String -> SDoc -> VM ()
- noV :: SDoc -> VM a
- traceNoV :: String -> SDoc -> VM a
- ensureV :: SDoc -> Bool -> VM ()
- traceEnsureV :: String -> SDoc -> Bool -> VM ()
- onlyIfV :: SDoc -> Bool -> VM a -> VM a
- tryV :: VM a -> VM (Maybe a)
- tryErrV :: VM a -> VM (Maybe a)
- maybeV :: SDoc -> VM (Maybe a) -> VM a
- traceMaybeV :: String -> SDoc -> VM (Maybe a) -> VM a
- orElseV :: VM a -> VM a -> VM a
- orElseErrV :: VM a -> VM a -> VM a
- fixV :: (a -> VM a) -> VM a

# The Vectorisation Monad

data VResult a

Vectorisation can either succeed with new envionment and a value, or return with failure (including a description of the reason for failure).

Constructors

Yes GlobalEnv LocalEnv a |
No SDoc |

newtype VM a

Constructors

VM |
Fields runVM :: Builtins -> GlobalEnv -> LocalEnv -> DsM (VResult a)

Instances

Monad VM |
Functor VM |
Applicative VM |
MonadIO VM |
HasDynFlags VM |

# Lifting

liftDs :: DsM a -> VM a

Lift a desugaring computation into the vectorisation monad.

# Error Handling

cantVectorise :: DynFlags -> String -> SDoc -> a

Throw a `pgmError` saying we can't vectorise something.

maybeCantVectorise :: DynFlags -> String -> SDoc -> Maybe a -> a

Like `fromJust`, but `pgmError` on Nothing.

maybeCantVectoriseM :: (Monad m, HasDynFlags m) => String -> SDoc -> m (Maybe a) -> m a

Like `maybeCantVectorise` but in a `Monad`.

# Debugging

emitVt :: String -> SDoc -> VM ()

Output a trace message if -ddump-vt-trace is active.

traceVt :: String -> SDoc -> VM ()

Output a trace message if -ddump-vt-trace is active.

dumpOptVt :: DumpFlag -> String -> SDoc -> VM ()

Dump the given program conditionally.

dumpVt :: String -> SDoc -> VM ()

Dump the given program unconditionally.

# Control

noV :: SDoc -> VM a

Return some result saying we've failed.

traceNoV :: String -> SDoc -> VM a

Like `traceNoV` but also emit some trace message to stderr.

ensureV :: SDoc -> Bool -> VM ()

If `True` then carry on, otherwise fail.

traceEnsureV :: String -> SDoc -> Bool -> VM ()

Like `ensureV` but if we fail then emit some trace message to stderr.

onlyIfV :: SDoc -> Bool -> VM a -> VM a

If `True` then return the first argument, otherwise fail.

tryV :: VM a -> VM (Maybe a)

Try some vectorisation computaton.

If it succeeds then return `Just` the result; otherwise, return `Nothing` without emitting a failure message.

tryErrV :: VM a -> VM (Maybe a)

Try some vectorisation computaton.

If it succeeds then return `Just` the result; otherwise, return `Nothing` after emitting a failure message.

maybeV :: SDoc -> VM (Maybe a) -> VM a

If `Just` then return the value, otherwise fail.

traceMaybeV :: String -> SDoc -> VM (Maybe a) -> VM a

Like `maybeV` but emit a message to stderr if we fail.

orElseV :: VM a -> VM a -> VM a

Try the first computation,

- if it succeeds then take the returned value,
- if it fails then run the second computation instead without emitting a failure message.

orElseErrV :: VM a -> VM a -> VM a

Try the first computation,

- if it succeeds then take the returned value,
- if it fails then run the second computation instead while emitting a failure message.

fixV :: (a -> VM a) -> VM a

Fixpoint in the vectorisation monad.