packages feed

futhask-1.0.0: src/Monad.hs

{-# LANGUAGE OverloadedStrings, MultilineStrings #-}

module Monad where
import qualified Futhark.Manifest as FM
import Backends
import CodeGen

monadBody manifest =
    """    
    -- *The Monad Transformer
    -- | The transformer that passes around the Futhark context.
    -- The @c@ parameter is skolem and prevents Futhark values from escaping the monad.

    type FutT c m = Futhask.FutT Context c m 
    -- **Predefined monads
    

    -- | lazy without side effects, no manual memory management possible
    type Fut c = Futhask.Fut Context c
    
    -- | strict with side effects, manual memory management possible
    type FutIO c = Futhask.FutIO Context c
    
    
    -- *Running the Transformer
    
    -- | Runs the transformer in a given context
    runFutTIn :: Context -> (forall c. FutT c m a) -> m a
    runFutTIn = Futhask.runFutTIn
    
    -- | Runs the transformer in a context with a list of options
    {-# NOINLINE runFutTWith #-}
    runFutTWith :: [ContextOption] -> (forall c. FutT c m a) -> m a
    runFutTWith = Futhask.runFutTWith
    
    -- | Runs the transformer with no context options
    runFutT :: (forall c. FutT c m a) -> m a
    runFutT = runFutTWith []
    
    -- | Runs the @Fut@ monad in a given context
    runFutIn :: Context -> (forall c. Fut c a) -> a
    runFutIn = Futhask.runFutIn
    
    
    -- | Runs the @Fut@ monad with in a context with a list of options
    runFutWith :: [ContextOption] -> (forall c. Fut c a) -> a
    runFutWith = Futhask.runFutWith
    
    -- | Runs the @Fut@ monad with no context options
    runFut :: (forall c. Fut c a) -> a
    runFut = Futhask.runFut
    
    -- *Misc
    
    -- | Lifts a futhark operation from the identity monad to any other monad
    pureFut :: Monad m => Fut c a -> FutT c m a
    pureFut = Futhask.pureFut
    
    -- | Maps a function to the monad transformer
    mapFutT :: (m a -> n b) -> FutT c m a -> FutT c n b
    mapFutT = Futhask.mapFutT
    
    -- | Same as @mapFutT@ but for two arguments
    map2FutT :: (m a -> n b -> k c) -> FutT c' m a -> FutT c' n b -> FutT c' k c
    map2FutT = Futhask.map2FutT
    
    -- *Profiling
    
    -- | Turns on profiling for the argument.
    profile :: MonadIO m => FutT c m a -> FutT c m a
    profile = Futhask.profile
    
    -- *Unsafe Lifting
    
    -- | Declares a @FutIO@ value as pure. The value must not consume any arguments or have side effects.
    {-# INLINE unsafeFromFutIO #-}
    unsafeFromFutIO :: Monad m => FutIO c a -> FutT c m a
    unsafeFromFutIO = Futhask.unsafeFromFutIO
    
    -- | Wraps a @(Context -> IO a)@ into the generic @FutT c m a@ . Useful for creating new abstractions from the @Raw@ interface functions. Operations should have no external side effects, or the function should be restricted to @MonadIO@.
    {-# INLINE unsafeLiftFromIO #-}
    unsafeLiftFromIO :: Monad m => (Context -> IO a) -> FutT c m a
    unsafeLiftFromIO = Futhask.unsafeLiftFromIO
    """