Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- newRef :: (pred a, RefCMD :<: instr) => ProgramT instr (Param2 exp pred) m (Ref a)
- newNamedRef :: (pred a, RefCMD :<: instr) => String -> ProgramT instr (Param2 exp pred) m (Ref a)
- initRef :: (pred a, RefCMD :<: instr) => exp a -> ProgramT instr (Param2 exp pred) m (Ref a)
- initNamedRef :: (pred a, RefCMD :<: instr) => String -> exp a -> ProgramT instr (Param2 exp pred) m (Ref a)
- getRef :: (pred a, FreeExp exp, FreePred exp a, RefCMD :<: instr, Monad m) => Ref a -> ProgramT instr (Param2 exp pred) m (exp a)
- setRef :: (pred a, RefCMD :<: instr) => Ref a -> exp a -> ProgramT instr (Param2 exp pred) m ()
- modifyRef :: (pred a, FreeExp exp, FreePred exp a, RefCMD :<: instr, Monad m) => Ref a -> (exp a -> exp a) -> ProgramT instr (Param2 exp pred) m ()
- unsafeFreezeRef :: (pred a, FreeExp exp, FreePred exp a, RefCMD :<: instr, Monad m) => Ref a -> ProgramT instr (Param2 exp pred) m (exp a)
- veryUnsafeFreezeRef :: (FreeExp exp, FreePred exp a) => Ref a -> exp a
- newArr :: (pred a, Integral i, Ix i, ArrCMD :<: instr) => exp i -> ProgramT instr (Param2 exp pred) m (Arr i a)
- newNamedArr :: (pred a, Integral i, Ix i, ArrCMD :<: instr) => String -> exp i -> ProgramT instr (Param2 exp pred) m (Arr i a)
- constArr :: (pred a, Integral i, Ix i, ArrCMD :<: instr) => [a] -> ProgramT instr (Param2 exp pred) m (Arr i a)
- constNamedArr :: (pred a, Integral i, Ix i, ArrCMD :<: instr) => String -> [a] -> ProgramT instr (Param2 exp pred) m (Arr i a)
- getArr :: (pred a, FreeExp exp, FreePred exp a, Integral i, Ix i, ArrCMD :<: instr, Monad m) => Arr i a -> exp i -> ProgramT instr (Param2 exp pred) m (exp a)
- setArr :: (pred a, Integral i, Ix i, ArrCMD :<: instr) => Arr i a -> exp i -> exp a -> ProgramT instr (Param2 exp pred) m ()
- copyArr :: (pred a, Integral i, Ix i, ArrCMD :<: instr) => (Arr i a, exp i) -> (Arr i a, exp i) -> exp i -> ProgramT instr (Param2 exp pred) m ()
- freezeArr :: (pred a, Integral i, Ix i, Num (exp i), ArrCMD :<: instr, Monad m) => Arr i a -> exp i -> ProgramT instr (Param2 exp pred) m (IArr i a)
- unsafeFreezeArr :: (pred a, Integral i, Ix i, ArrCMD :<: instr) => Arr i a -> ProgramT instr (Param2 exp pred) m (IArr i a)
- thawArr :: (pred a, Integral i, Ix i, Num (exp i), ArrCMD :<: instr, Monad m) => IArr i a -> exp i -> ProgramT instr (Param2 exp pred) m (Arr i a)
- unsafeThawArr :: (pred a, Integral i, Ix i, ArrCMD :<: instr) => IArr i a -> ProgramT instr (Param2 exp pred) m (Arr i a)
- iff :: ControlCMD :<: instr => exp Bool -> ProgramT instr (Param2 exp pred) m () -> ProgramT instr (Param2 exp pred) m () -> ProgramT instr (Param2 exp pred) m ()
- ifE :: (pred a, FreeExp exp, FreePred exp a, ControlCMD :<: instr, RefCMD :<: instr, Monad m) => exp Bool -> ProgramT instr (Param2 exp pred) m (exp a) -> ProgramT instr (Param2 exp pred) m (exp a) -> ProgramT instr (Param2 exp pred) m (exp a)
- while :: ControlCMD :<: instr => ProgramT instr (Param2 exp pred) m (exp Bool) -> ProgramT instr (Param2 exp pred) m () -> ProgramT instr (Param2 exp pred) m ()
- for :: (FreeExp exp, ControlCMD :<: instr, Integral n, pred n, FreePred exp n) => IxRange (exp n) -> (exp n -> ProgramT instr (Param2 exp pred) m ()) -> ProgramT instr (Param2 exp pred) m ()
- break :: ControlCMD :<: instr => ProgramT instr (Param2 exp pred) m ()
- assert :: ControlCMD :<: instr => exp Bool -> String -> ProgramT instr (Param2 exp pred) m ()
- unsafeSwap :: (IsPointer a, PtrCMD :<: instr) => a -> a -> ProgramT instr (Param2 exp pred) m ()
- fopen :: FileCMD :<: instr => FilePath -> IOMode -> ProgramT instr (Param2 exp pred) m Handle
- fclose :: FileCMD :<: instr => Handle -> ProgramT instr (Param2 exp pred) m ()
- feof :: (FreeExp exp, FreePred exp Bool, FileCMD :<: instr, Monad m) => Handle -> ProgramT instr (Param2 exp pred) m (exp Bool)
- class PrintfType r where
- fprintf :: PrintfType r => Handle -> String -> r
- fput :: forall instr exp pred a m. (Formattable a, FreePred exp a, FileCMD :<: instr) => Handle -> String -> exp a -> String -> ProgramT instr (Param2 exp pred) m ()
- fget :: (Formattable a, pred a, FreeExp exp, FreePred exp a, FileCMD :<: instr, Monad m) => Handle -> ProgramT instr (Param2 exp pred) m (exp a)
- printf :: PrintfType r => String -> r
- newPtr :: (pred a, C_CMD :<: instr) => ProgramT instr (Param2 exp pred) m (Ptr a)
- newNamedPtr :: (pred a, C_CMD :<: instr) => String -> ProgramT instr (Param2 exp pred) m (Ptr a)
- ptrToArr :: C_CMD :<: instr => Ptr a -> ProgramT instr (Param2 exp pred) m (Arr i a)
- newObject :: C_CMD :<: instr => String -> Bool -> ProgramT instr (Param2 exp pred) m Object
- newNamedObject :: C_CMD :<: instr => String -> String -> Bool -> ProgramT instr (Param2 exp pred) m Object
- addInclude :: C_CMD :<: instr => String -> ProgramT instr (Param2 exp pred) m ()
- addDefinition :: C_CMD :<: instr => Definition -> ProgramT instr (Param2 exp pred) m ()
- addExternFun :: (pred res, C_CMD :<: instr) => String -> proxy res -> [FunArg exp pred] -> ProgramT instr (Param2 exp pred) m ()
- addExternProc :: C_CMD :<: instr => String -> [FunArg exp pred] -> ProgramT instr (Param2 exp pred) m ()
- callFun :: (pred a, FreeExp exp, FreePred exp a, C_CMD :<: instr, Monad m) => String -> [FunArg exp pred] -> ProgramT instr (Param2 exp pred) m (exp a)
- callProc :: C_CMD :<: instr => String -> [FunArg exp pred] -> ProgramT instr (Param2 exp pred) m ()
- callProcAssign :: (Assignable obj, C_CMD :<: instr) => obj -> String -> [FunArg exp pred] -> ProgramT instr (Param2 exp pred) m ()
- externFun :: forall instr m exp pred res. (pred res, FreeExp exp, FreePred exp res, C_CMD :<: instr, Monad m) => String -> [FunArg exp pred] -> ProgramT instr (Param2 exp pred) m (exp res)
- externProc :: (C_CMD :<: instr, Monad m) => String -> [FunArg exp pred] -> ProgramT instr (Param2 exp pred) m ()
- inModule :: C_CMD :<: instr => String -> ProgramT instr (Param2 exp pred) m () -> ProgramT instr (Param2 exp pred) m ()
- getTime :: (pred Double, FreeExp exp, FreePred exp Double, C_CMD :<: instr, Monad m) => ProgramT instr (Param2 exp pred) m (exp Double)
- valArg :: pred a => exp a -> FunArg exp pred
- refArg :: (pred a, Arg RefArg pred) => Ref a -> FunArg exp pred
- arrArg :: (pred a, Arg ArrArg pred) => Arr i a -> FunArg exp pred
- iarrArg :: (pred a, Arg IArrArg pred) => IArr i a -> FunArg exp pred
- ptrArg :: (pred a, Arg PtrArg pred) => Ptr a -> FunArg exp pred
- objArg :: Object -> FunArg exp pred
- strArg :: String -> FunArg exp pred
- constArg :: String -> String -> FunArg exp pred
- addr :: FunArg exp pred -> FunArg exp pred
- deref :: FunArg exp pred -> FunArg exp pred
- offset :: Integral i => FunArg exp pred -> exp i -> FunArg exp pred
- runIO :: (EvalExp exp, InterpBi instr IO (Param1 pred), HBifunctor instr) => Program instr (Param2 exp pred) a -> IO a
- captureIO :: (EvalExp exp, InterpBi instr IO (Param1 pred), HBifunctor instr) => Program instr (Param2 exp pred) a -> String -> IO String
References
newRef :: (pred a, RefCMD :<: instr) => ProgramT instr (Param2 exp pred) m (Ref a) Source #
Create an uninitialized reference
Create an uninitialized named reference
The provided base name may be appended with a unique identifier to avoid name collisions.
Create an initialized reference
:: (pred a, RefCMD :<: instr) | |
=> String | Base name |
-> exp a | Initial value |
-> ProgramT instr (Param2 exp pred) m (Ref a) |
Create an initialized named reference
The provided base name may be appended with a unique identifier to avoid name collisions.
getRef :: (pred a, FreeExp exp, FreePred exp a, RefCMD :<: instr, Monad m) => Ref a -> ProgramT instr (Param2 exp pred) m (exp a) Source #
Get the contents of a reference
setRef :: (pred a, RefCMD :<: instr) => Ref a -> exp a -> ProgramT instr (Param2 exp pred) m () Source #
Set the contents of a reference
modifyRef :: (pred a, FreeExp exp, FreePred exp a, RefCMD :<: instr, Monad m) => Ref a -> (exp a -> exp a) -> ProgramT instr (Param2 exp pred) m () Source #
Modify the contents of reference
unsafeFreezeRef :: (pred a, FreeExp exp, FreePred exp a, RefCMD :<: instr, Monad m) => Ref a -> ProgramT instr (Param2 exp pred) m (exp a) Source #
Freeze the contents of reference (only safe if the reference is not updated as long as the resulting value is alive)
veryUnsafeFreezeRef :: (FreeExp exp, FreePred exp a) => Ref a -> exp a Source #
Read the value of a reference without returning in the monad
WARNING: Don't use this function unless you really know what you are doing.
It is almost always better to use unsafeFreezeRef
instead.
veryUnsafeFreezeRef
behaves predictably when doing code generation, but it
can give strange results when running in IO
, as explained here:
http://fun-discoveries.blogspot.se/2015/09/strictness-can-fix-non-termination.html
Arrays
:: (pred a, Integral i, Ix i, ArrCMD :<: instr) | |
=> exp i | Length |
-> ProgramT instr (Param2 exp pred) m (Arr i a) |
Create an uninitialized array
:: (pred a, Integral i, Ix i, ArrCMD :<: instr) | |
=> String | Base name |
-> exp i | Length |
-> ProgramT instr (Param2 exp pred) m (Arr i a) |
Create an uninitialized named array
The provided base name may be appended with a unique identifier to avoid name collisions.
:: (pred a, Integral i, Ix i, ArrCMD :<: instr) | |
=> [a] | Initial contents |
-> ProgramT instr (Param2 exp pred) m (Arr i a) |
Create an array and initialize it with a constant list
:: (pred a, Integral i, Ix i, ArrCMD :<: instr) | |
=> String | Base name |
-> [a] | Initial contents |
-> ProgramT instr (Param2 exp pred) m (Arr i a) |
Create a named array and initialize it with a constant list
The provided base name may be appended with a unique identifier to avoid name collisions.
getArr :: (pred a, FreeExp exp, FreePred exp a, Integral i, Ix i, ArrCMD :<: instr, Monad m) => Arr i a -> exp i -> ProgramT instr (Param2 exp pred) m (exp a) Source #
Get an element of an array
setArr :: (pred a, Integral i, Ix i, ArrCMD :<: instr) => Arr i a -> exp i -> exp a -> ProgramT instr (Param2 exp pred) m () Source #
Set an element of an array
:: (pred a, Integral i, Ix i, ArrCMD :<: instr) | |
=> (Arr i a, exp i) | (destination,offset) |
-> (Arr i a, exp i) | (source,offset |
-> exp i | Number of elements |
-> ProgramT instr (Param2 exp pred) m () |
Copy the contents of an array to another array. The number of elements to copy must not be greater than the number of allocated elements in either array.
:: (pred a, Integral i, Ix i, Num (exp i), ArrCMD :<: instr, Monad m) | |
=> Arr i a | |
-> exp i | Length of new array |
-> ProgramT instr (Param2 exp pred) m (IArr i a) |
Freeze a mutable array to an immutable one. This involves copying the array to a newly allocated one.
unsafeFreezeArr :: (pred a, Integral i, Ix i, ArrCMD :<: instr) => Arr i a -> ProgramT instr (Param2 exp pred) m (IArr i a) Source #
Freeze a mutable array to an immutable one without making a copy. This is generally only safe if the the mutable array is not updated as long as the immutable array is alive.
:: (pred a, Integral i, Ix i, Num (exp i), ArrCMD :<: instr, Monad m) | |
=> IArr i a | |
-> exp i | Number of elements to copy |
-> ProgramT instr (Param2 exp pred) m (Arr i a) |
Thaw an immutable array to a mutable one. This involves copying the array to a newly allocated one.
unsafeThawArr :: (pred a, Integral i, Ix i, ArrCMD :<: instr) => IArr i a -> ProgramT instr (Param2 exp pred) m (Arr i a) Source #
Thaw an immutable array to a mutable one without making a copy. This is generally only safe if the the mutable array is not updated as long as the immutable array is alive.
Control flow
:: ControlCMD :<: instr | |
=> exp Bool | Condition |
-> ProgramT instr (Param2 exp pred) m () | True branch |
-> ProgramT instr (Param2 exp pred) m () | False branch |
-> ProgramT instr (Param2 exp pred) m () |
Conditional statement
:: (pred a, FreeExp exp, FreePred exp a, ControlCMD :<: instr, RefCMD :<: instr, Monad m) | |
=> exp Bool | Condition |
-> ProgramT instr (Param2 exp pred) m (exp a) | True branch |
-> ProgramT instr (Param2 exp pred) m (exp a) | False branch |
-> ProgramT instr (Param2 exp pred) m (exp a) |
Conditional statement that returns an expression
:: ControlCMD :<: instr | |
=> ProgramT instr (Param2 exp pred) m (exp Bool) | Continue condition |
-> ProgramT instr (Param2 exp pred) m () | Loop body |
-> ProgramT instr (Param2 exp pred) m () |
While loop
:: (FreeExp exp, ControlCMD :<: instr, Integral n, pred n, FreePred exp n) | |
=> IxRange (exp n) | Index range |
-> (exp n -> ProgramT instr (Param2 exp pred) m ()) | Loop body |
-> ProgramT instr (Param2 exp pred) m () |
For loop
break :: ControlCMD :<: instr => ProgramT instr (Param2 exp pred) m () Source #
Break out from a loop
:: ControlCMD :<: instr | |
=> exp Bool | Expression that should be true |
-> String | Message in case of failure |
-> ProgramT instr (Param2 exp pred) m () |
Assertion
Pointer operations
unsafeSwap :: (IsPointer a, PtrCMD :<: instr) => a -> a -> ProgramT instr (Param2 exp pred) m () Source #
Swap two pointers
This is generally an unsafe operation. E.g. it can be used to make a reference to a data structure escape the scope of the data.
The IsPointer
class ensures that the operation is only possible for types
that are represented as pointers in C.
File handling
fopen :: FileCMD :<: instr => FilePath -> IOMode -> ProgramT instr (Param2 exp pred) m Handle Source #
Open a file
feof :: (FreeExp exp, FreePred exp Bool, FileCMD :<: instr, Monad m) => Handle -> ProgramT instr (Param2 exp pred) m (exp Bool) Source #
Check for end of file
class PrintfType r where Source #
Instances
(Formattable a, PrintfType r, exp ~ PrintfExp r) => PrintfType (exp a -> r) Source # | |
((FileCMD :: (Type -> Type, (Type -> Type, (Type -> Constraint, Type))) -> Type -> Type) :<: instr, a ~ ()) => PrintfType (ProgramT instr (Param2 exp pred) m a) Source # | |
fprintf :: PrintfType r => Handle -> String -> r Source #
Print to a handle. Accepts a variable number of arguments.
:: forall instr exp pred a m. (Formattable a, FreePred exp a, FileCMD :<: instr) | |
=> Handle | |
-> String | Prefix |
-> exp a | Expression to print |
-> String | Suffix |
-> ProgramT instr (Param2 exp pred) m () |
Put a single value to a handle
fget :: (Formattable a, pred a, FreeExp exp, FreePred exp a, FileCMD :<: instr, Monad m) => Handle -> ProgramT instr (Param2 exp pred) m (exp a) Source #
Get a single value from a handle
printf :: PrintfType r => String -> r Source #
Print to stdout
. Accepts a variable number of arguments.
C-specific commands
newPtr :: (pred a, C_CMD :<: instr) => ProgramT instr (Param2 exp pred) m (Ptr a) Source #
Create a null pointer
Create a named null pointer
The provided base name may be appended with a unique identifier to avoid name collisions.
ptrToArr :: C_CMD :<: instr => Ptr a -> ProgramT instr (Param2 exp pred) m (Arr i a) Source #
Cast a pointer to an array
addInclude :: C_CMD :<: instr => String -> ProgramT instr (Param2 exp pred) m () Source #
Add an #include
statement to the generated code
addDefinition :: C_CMD :<: instr => Definition -> ProgramT instr (Param2 exp pred) m () Source #
Add a global definition to the generated code
Can be used conveniently as follows:
{-# LANGUAGE QuasiQuotes #-} import Language.Embedded.Imperative import Language.C.Quote.C prog = do ... addDefinition myCFunction ... where myCFunction = [cedecl| void my_C_function( ... ) { // C code // goes here } |]
:: (pred res, C_CMD :<: instr) | |
=> String | Function name |
-> proxy res | Proxy for result type |
-> [FunArg exp pred] | Arguments (only used to determine types) |
-> ProgramT instr (Param2 exp pred) m () |
Declare an external function
:: C_CMD :<: instr | |
=> String | Procedure name |
-> [FunArg exp pred] | Arguments (only used to determine types) |
-> ProgramT instr (Param2 exp pred) m () |
Declare an external procedure
:: (pred a, FreeExp exp, FreePred exp a, C_CMD :<: instr, Monad m) | |
=> String | Function name |
-> [FunArg exp pred] | Arguments |
-> ProgramT instr (Param2 exp pred) m (exp a) |
Call a function
:: C_CMD :<: instr | |
=> String | Procedure name |
-> [FunArg exp pred] | Arguments |
-> ProgramT instr (Param2 exp pred) m () |
Call a procedure
:: (Assignable obj, C_CMD :<: instr) | |
=> obj | Object to which the result should be assigned |
-> String | Procedure name |
-> [FunArg exp pred] | Arguments |
-> ProgramT instr (Param2 exp pred) m () |
Call a procedure and assign its result
:: forall instr m exp pred res. (pred res, FreeExp exp, FreePred exp res, C_CMD :<: instr, Monad m) | |
=> String | Function name |
-> [FunArg exp pred] | Arguments |
-> ProgramT instr (Param2 exp pred) m (exp res) |
Declare and call an external function
:: (C_CMD :<: instr, Monad m) | |
=> String | Procedure name |
-> [FunArg exp pred] | Arguments |
-> ProgramT instr (Param2 exp pred) m () |
Declare and call an external procedure
inModule :: C_CMD :<: instr => String -> ProgramT instr (Param2 exp pred) m () -> ProgramT instr (Param2 exp pred) m () Source #
Generate code into another translation unit
getTime :: (pred Double, FreeExp exp, FreePred exp Double, C_CMD :<: instr, Monad m) => ProgramT instr (Param2 exp pred) m (exp Double) Source #
Get current time as number of seconds passed today
iarrArg :: (pred a, Arg IArrArg pred) => IArr i a -> FunArg exp pred Source #
Immutable array argument
addr :: FunArg exp pred -> FunArg exp pred Source #
Modifier that takes the address of another argument
offset :: Integral i => FunArg exp pred -> exp i -> FunArg exp pred Source #
Add an offset to another argument