imperative-edsl-0.4.1: 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 CallCMD which is C-specific.

Synopsis

References

data Ref a Source

Mutable reference

Constructors

RefComp VarId 
RefEval (IORef a) 

Instances

ToIdent (Ref a) Source

Identifiers from references

data RefCMD exp prog a where Source

Commands for mutable references

Constructors

NewRef :: VarPred exp a => RefCMD exp prog (Ref a) 
InitRef :: VarPred exp a => exp a -> RefCMD exp prog (Ref a) 
GetRef :: VarPred exp a => Ref a -> RefCMD exp prog (exp a) 
SetRef :: VarPred exp a => Ref a -> exp a -> RefCMD exp prog () 

Instances

HFunctor * * (RefCMD exp) Source 
CompExp exp => DryInterp (RefCMD exp) Source 
EvalExp exp => Interp (RefCMD exp) IO Source 
type IExp (RefCMD e) = e Source 
type IExp ((:+:) (* -> *) * (RefCMD e) i) = e Source 

Arrays

data Arr n a Source

Mutable array

Constructors

ArrComp String 
ArrEval (IOArray n a) 

Instances

ToIdent (Arr i a) Source

Identifiers from arrays

data ArrCMD exp prog a where Source

Commands for mutable arrays

Constructors

NewArr :: (VarPred exp a, VarPred exp n, Integral n, Ix n) => exp n -> ArrCMD exp prog (Arr n a) 
NewArr_ :: (VarPred exp a, VarPred exp n, Integral n, Ix n) => ArrCMD exp prog (Arr n a) 
GetArr :: (VarPred exp a, Integral n, Ix n) => exp n -> Arr n a -> ArrCMD exp prog (exp a) 
SetArr :: (Integral n, Ix n) => exp n -> exp a -> Arr n a -> ArrCMD exp prog () 

Instances

HFunctor * * (ArrCMD exp) Source 
CompExp exp => DryInterp (ArrCMD exp) Source 
EvalExp exp => Interp (ArrCMD exp) IO Source 
type IExp (ArrCMD e) = e Source 
type IExp ((:+:) (* -> *) * (ArrCMD e) i) = e Source 

Control flow

data ControlCMD exp prog a where Source

Constructors

If :: exp Bool -> prog () -> prog () -> ControlCMD exp prog () 
While :: prog (exp Bool) -> prog () -> ControlCMD exp prog () 
For :: (VarPred exp n, Integral n) => exp n -> exp n -> (exp n -> prog ()) -> ControlCMD exp prog () 
Break :: ControlCMD exp prog () 

Instances

HFunctor * * (ControlCMD exp) Source 
DryInterp (ControlCMD exp) Source 
EvalExp exp => Interp (ControlCMD exp) IO Source 
type IExp (ControlCMD e) = e Source 
type IExp ((:+:) (* -> *) * (ControlCMD e) i) = e Source 

File handling

data Handle Source

File handle

Instances

ToIdent Handle Source

Identifiers from handles

stdin :: Handle Source

Handle to stdin

stdout :: Handle Source

Handle to stdout

data FileCMD exp prog a where Source

Constructors

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

Instances

HFunctor * * (FileCMD exp) Source 
CompExp exp => DryInterp (FileCMD exp) Source 
EvalExp exp => Interp (FileCMD exp) IO Source 
type IExp (FileCMD e) = e Source 
type IExp ((:+:) (* -> *) * (FileCMD e) i) = e Source 

data PrintfArg exp where Source

Constructors

PrintfArg :: (PrintfArg a, VarPred exp a) => exp a -> PrintfArg exp 

Abstract objects

data Object Source

Constructors

Object 

Instances

data ObjectCMD exp prog a where Source

Constructors

NewObject :: String -> ObjectCMD exp prog Object 
InitObject :: String -> Bool -> String -> [FunArg exp] -> ObjectCMD exp prog Object 

Instances

HFunctor * * (ObjectCMD exp) Source 
DryInterp (ObjectCMD exp) Source 
Interp (ObjectCMD exp) IO Source 
type IExp (ObjectCMD e) = e Source 
type IExp ((:+:) (* -> *) * (ObjectCMD e) i) = e Source 

External function calls (C-specific)

data FunArg exp where Source

Constructors

FunArg :: Arg arg => arg exp -> FunArg exp 

Instances

type VarPredCast exp1 exp2 = forall a b. VarPred exp1 a => Proxy a -> (VarPred exp2 a => b) -> b Source

Evidence that VarPred exp1 implies VarPred exp2

class Arg arg where Source

Methods

mkArg :: CompExp exp => arg exp -> CGen Exp Source

mkParam :: CompExp exp => arg exp -> CGen Param Source

mapArg :: VarPredCast exp1 exp2 -> (forall a. VarPred exp1 a => exp1 a -> exp2 a) -> arg exp1 -> arg exp2 Source

Map over the expression(s) in an argument

mapMArg :: Monad m => VarPredCast exp1 exp2 -> (forall a. VarPred exp1 a => exp1 a -> m (exp2 a)) -> arg exp1 -> m (arg exp2) Source

Monadic map over the expression(s) in an argument

Instances

Arg FunArg Source 
Arg ArrArg Source 
Arg RefArg Source 
Arg ValArg Source 
Arg (StrArg (* -> *)) Source 
Arg (ObjArg (* -> *)) Source 
Arg arg => Arg (Addr (* -> *) arg) Source 

data CallCMD exp prog a where Source

Constructors

AddInclude :: String -> CallCMD exp prog () 
AddDefinition :: Definition -> CallCMD exp prog () 
AddExternFun :: VarPred exp res => String -> proxy (exp res) -> [FunArg exp] -> CallCMD exp prog () 
AddExternProc :: String -> [FunArg exp] -> CallCMD exp prog () 
CallFun :: VarPred exp a => String -> [FunArg exp] -> CallCMD exp prog (exp a) 
CallProc :: String -> [FunArg exp] -> CallCMD exp prog () 

Instances

HFunctor * * (CallCMD exp) Source 
CompExp exp => DryInterp (CallCMD exp) Source 
EvalExp exp => Interp (CallCMD exp) IO Source 
type IExp (CallCMD e) = e Source 
type IExp ((:+:) (* -> *) * (CallCMD e) i) = e Source