ghc-7.0.4: The GHC API

Vectorise.Monad.Base

Contents

- The Vectorisation Monad
- Lifting
- Error Handling
- Control

Description

The Vectorisation monad.

Synopsis

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

# The Vectorisation Monad

data VResult a Source

Vectorisation can either succeed with new envionment and a value, or return with failure.

Constructors

Yes GlobalEnv LocalEnv a |
No |

newtype VM a Source

Constructors

VM |

Fields

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

Instances

Monad VM |

# Lifting

liftDs :: DsM a -> VM aSource

Lift a desugaring computation into the vectorisation monad.

# Error Handling

cantVectorise :: String -> SDoc -> aSource

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

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

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

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

Like `maybeCantVectorise` but in a `Monad`.

# Control

noV :: VM aSource

Return some result saying we've failed.

traceNoV :: String -> SDoc -> VM aSource

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

ensureV :: Bool -> VM ()Source

If `True` then carry on, otherwise fail.

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

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

onlyIfV :: Bool -> VM a -> VM aSource

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

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

Try some vectorisation computaton. If it succeeds then return `Just` the result, otherwise return `Nothing`.

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

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

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

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

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

Try the first computation, if it succeeds then take the returned value, if it fails then run the second computation instead.

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

Fixpoint in the vectorisation monad.