imperative-edsl-0.5: Deep embedding of imperative programs with code generation

Safe HaskellNone
LanguageHaskell2010

Language.Embedded.Imperative.CMD

Contents

Description

Imperative commands. These commands can be used with the Program monad, and different command types can be combined using (:+:).

These commands are general imperative constructs independent of the back end, except for C_CMD which is C-specific.

Synopsis

References

data Ref a Source

Mutable reference

Constructors

RefComp VarId 
RefEval (IORef a) 

Instances

data RefCMD fs a where Source

Commands for mutable references

Constructors

NewRef :: pred a => String -> RefCMD (Param3 prog exp pred) (Ref a) 
InitRef :: pred a => String -> exp a -> RefCMD (Param3 prog exp pred) (Ref a) 
GetRef :: pred a => Ref a -> RefCMD (Param3 prog exp pred) (Val a) 
SetRef :: pred a => Ref a -> exp a -> RefCMD (Param3 prog exp pred) () 
UnsafeFreezeRef :: pred a => Ref a -> RefCMD (Param3 prog exp pred) (Val a) 

Instances

HFunctor k * ((,) (* -> *) ((,) (* -> Constraint) *)) (RefCMD (k -> *)) Source 
HBifunctor * * ((,) (* -> Constraint) *) (RefCMD (* -> *)) Source 
(:<:) ((,) (* -> *) ((,) (* -> *) ((,) (* -> Constraint) *))) * (RefCMD (* -> *)) instr => Reexpressible * ((,) (* -> Constraint) *) (RefCMD (* -> *)) instr Source 
InterpBi ((,) (* -> Constraint) *) * (RefCMD (* -> *)) IO (Param1 (* -> Constraint) pred) Source 
DryInterp ((,) (* -> *) ((,) (* -> Constraint) *)) (RefCMD (* -> *)) Source 

Arrays

data Arr i a Source

Mutable array

Constructors

ArrComp VarId 
ArrEval (IORef (IOArray i a)) 

Instances

data IArr i a Source

Immutable array

Constructors

IArrComp VarId 
IArrEval (Array i a) 

Instances

data ArrCMD fs a where Source

Commands for mutable arrays

Constructors

NewArr :: (pred a, Integral i, Ix i) => String -> exp i -> ArrCMD (Param3 prog exp pred) (Arr i a) 
InitArr :: (pred a, Integral i, Ix i) => String -> [a] -> ArrCMD (Param3 prog exp pred) (Arr i a) 
GetArr :: (pred a, Integral i, Ix i) => exp i -> Arr i a -> ArrCMD (Param3 prog exp pred) (Val a) 
SetArr :: (pred a, Integral i, Ix i) => exp i -> exp a -> Arr i a -> ArrCMD (Param3 prog exp pred) () 
CopyArr :: (pred a, Integral i, Ix i) => Arr i a -> Arr i a -> exp i -> ArrCMD (Param3 prog exp pred) () 
UnsafeFreezeArr :: (pred a, Integral i, Ix i) => Arr i a -> ArrCMD (Param3 prog exp pred) (IArr i a) 
UnsafeThawArr :: (pred a, Integral i, Ix i) => IArr i a -> ArrCMD (Param3 prog exp pred) (Arr i a) 

Instances

HFunctor k * ((,) (* -> *) ((,) (* -> Constraint) *)) (ArrCMD (k -> *)) Source 
HBifunctor * * ((,) (* -> Constraint) *) (ArrCMD (* -> *)) Source 
(:<:) ((,) (* -> *) ((,) (* -> *) ((,) (* -> Constraint) *))) * (ArrCMD (* -> *)) instr => Reexpressible * ((,) (* -> Constraint) *) (ArrCMD (* -> *)) instr Source 
InterpBi ((,) (* -> Constraint) *) * (ArrCMD (* -> *)) IO (Param1 (* -> Constraint) pred) Source 
DryInterp ((,) (* -> *) ((,) (* -> Constraint) *)) (ArrCMD (* -> *)) Source 

Control flow

data Border i Source

Constructors

Incl i 
Excl i 

Instances

Functor Border Source 
Foldable Border Source 
Traversable Border Source 
Eq i => Eq (Border i) Source 
Num i => Num (Border i) Source

fromInteger gives an inclusive border. No other methods defined.

Show i => Show (Border i) Source 

type IxRange i = (i, Int, Border i) Source

Index range

(lo,step,hi)

lo gives the start index; step gives the step length; hi gives the stop index which may be inclusive or exclusive.

data ControlCMD fs a where Source

Constructors

If :: exp Bool -> prog () -> prog () -> ControlCMD (Param3 prog exp pred) () 
While :: prog (exp Bool) -> prog () -> ControlCMD (Param3 prog exp pred) () 
For :: (pred i, Integral i) => IxRange (exp i) -> (Val i -> prog ()) -> ControlCMD (Param3 prog exp pred) () 
Break :: ControlCMD (Param3 prog exp pred) () 
Assert :: exp Bool -> String -> ControlCMD (Param3 prog exp pred) () 

Instances

HFunctor * * ((,) (* -> *) ((,) (* -> Constraint) *)) ControlCMD Source 
HBifunctor * * ((,) (* -> Constraint) *) ControlCMD Source 
(:<:) ((,) (* -> *) ((,) (* -> *) ((,) (* -> Constraint) *))) * ControlCMD instr => Reexpressible * ((,) (* -> Constraint) *) ControlCMD instr Source 
DryInterp ((,) (* -> *) ((,) (* -> Constraint) *)) ControlCMD Source 
InterpBi ((,) (* -> Constraint) *) * ControlCMD IO (Param1 (* -> Constraint) pred) Source 

Pointers

class ToIdent a => IsPointer a where Source

Types that are represented as a pointers in C

Methods

runSwapPtr :: a -> a -> IO () Source

Instances

data PtrCMD fs a where Source

Constructors

SwapPtr :: IsPointer a => a -> a -> PtrCMD (Param3 prog exp pred) () 

Instances

HFunctor k * ((,) k ((,) k *)) (PtrCMD (k -> *) k k) Source 
HBifunctor * k ((,) k *) (PtrCMD (* -> *) (k -> *) k) Source 
(:<:) ((,) (* -> *) ((,) (k -> *) ((,) k1 *))) * (PtrCMD (* -> *) (k -> *) k1) instr => Reexpressible k ((,) k *) (PtrCMD (* -> *) (k -> *) k) instr Source 
InterpBi ((,) k *) * (PtrCMD (* -> *) (* -> *) k) IO (Param1 k pred) Source 
DryInterp ((,) k ((,) k *)) (PtrCMD (* -> *) k k) Source 

File handling

data Handle Source

File handle

Instances

stdin :: Handle Source

Handle to stdin

stdout :: Handle Source

Handle to stdout

data PrintfArg exp where Source

Constructors

PrintfArg :: PrintfArg a => exp a -> PrintfArg exp 

mapPrintfArg :: (forall a. exp1 a -> exp2 a) -> PrintfArg exp1 -> PrintfArg exp2 Source

mapPrintfArgM :: Monad m => (forall a. exp1 a -> m (exp2 a)) -> PrintfArg exp1 -> m (PrintfArg exp2) Source

data FileCMD fs a where Source

Constructors

FOpen :: FilePath -> IOMode -> FileCMD (Param3 prog exp pred) Handle 
FClose :: Handle -> FileCMD (Param3 prog exp pred) () 
FEof :: Handle -> FileCMD (Param3 prog exp pred) (Val Bool) 
FPrintf :: Handle -> String -> [PrintfArg exp] -> FileCMD (Param3 prog exp pred) () 
FGet :: (pred a, Formattable a) => Handle -> FileCMD (Param3 prog exp pred) (Val a) 

Instances

HFunctor k * ((,) (* -> *) ((,) (* -> Constraint) *)) (FileCMD (k -> *)) Source 
HBifunctor * * ((,) (* -> Constraint) *) (FileCMD (* -> *)) Source 
(:<:) ((,) (* -> *) ((,) (* -> *) ((,) (* -> Constraint) *))) * (FileCMD (* -> *)) instr => Reexpressible * ((,) (* -> Constraint) *) (FileCMD (* -> *)) instr Source 
InterpBi ((,) (* -> Constraint) *) * (FileCMD (* -> *)) IO (Param1 (* -> Constraint) pred) Source 
DryInterp ((,) (* -> *) ((,) (* -> Constraint) *)) (FileCMD (* -> *)) Source 

C-specific commands

newtype Ptr a Source

Pointer

Constructors

PtrComp 

Fields

ptrId :: VarId
 

Instances

class Arg arg pred where Source

Methods

mkArg :: arg pred -> CGen Exp Source

mkParam :: arg pred -> CGen Param Source

data FunArg exp pred where Source

Constructors

ValArg :: pred a => exp a -> FunArg exp pred 
AddrArg :: FunArg exp pred -> FunArg exp pred 
DerefArg :: FunArg exp pred -> FunArg exp pred 
FunArg :: Arg arg pred => arg pred -> FunArg exp pred 

Instances

CompExp exp => Arg (* -> Constraint) (FunArg * exp) CType Source 

mapFunArg :: (forall a. exp1 a -> exp2 a) -> FunArg exp1 pred -> FunArg exp2 pred Source

mapFunArgM :: Monad m => (forall a. exp1 a -> m (exp2 a)) -> FunArg exp1 pred -> m (FunArg exp2 pred) Source

data C_CMD fs a where Source

Constructors

NewPtr :: pred a => String -> C_CMD (Param3 prog exp pred) (Ptr a) 
PtrToArr :: Ptr a -> C_CMD (Param3 prog exp pred) (Arr i a) 
NewObject :: String -> String -> Bool -> C_CMD (Param3 prog exp pred) Object 
AddInclude :: String -> C_CMD (Param3 prog exp pred) () 
AddDefinition :: Definition -> C_CMD (Param3 prog exp pred) () 
AddExternFun :: pred res => String -> proxy res -> [FunArg exp pred] -> C_CMD (Param3 prog exp pred) () 
AddExternProc :: String -> [FunArg exp pred] -> C_CMD (Param3 prog exp pred) () 
CallFun :: pred a => String -> [FunArg exp pred] -> C_CMD (Param3 prog exp pred) (Val a) 
CallProc :: Assignable obj => Maybe obj -> String -> [FunArg exp pred] -> C_CMD (Param3 prog exp pred) () 
InModule :: String -> prog () -> C_CMD (Param3 prog exp pred) () 

Instances

HFunctor * * ((,) (* -> *) ((,) (* -> Constraint) *)) C_CMD Source 
HBifunctor * * ((,) (* -> Constraint) *) C_CMD Source 
(:<:) ((,) (* -> *) ((,) (* -> *) ((,) (* -> Constraint) *))) * C_CMD instr => Reexpressible * ((,) (* -> Constraint) *) C_CMD instr Source 
DryInterp ((,) (* -> *) ((,) (* -> Constraint) *)) C_CMD Source 
InterpBi ((,) (* -> Constraint) *) * C_CMD IO (Param1 (* -> Constraint) pred) Source