Safe Haskell | None |
---|---|
Language | Haskell2010 |
Deep embedding of imperative programs with code generation. This is the main module for users who want to write imperative programs.
The Program
type is parameterized by an instruction set that can be
combined in a modular way; e.g:
type MyProg exp a =Program
(RefCMD
exp:+:
FileCMD
exp) a
Also, instructions are parameterized on the expression language.
Some examples of using the library are found in the examples
directory.
- module Control.Monad
- data ProgramT k instr fs m a :: forall k. ((* -> *, k) -> * -> *) -> k -> (* -> *) -> * -> *
- type Program k instr fs = ProgramT k instr fs Identity
- interpretT :: (Interp * k i m fs, HFunctor * * k i, Monad m) => (forall b. n b -> m b) -> ProgramT k i fs n a -> m a
- interpret :: (Interp * k i m fs, HFunctor * * k i, Monad m) => Program k i fs a -> m a
- interpretBiT :: (InterpBi * k i m fs, HBifunctor * * k i, Functor m, Monad m, Monad n) => (forall b. exp b -> m b) -> (forall b. n b -> m b) -> ProgramT (* -> *, k) i ((,) (* -> *) k exp fs) n a -> m a
- interpretBi :: (InterpBi * k i m fs, HBifunctor * * k i, Functor m, Monad m) => (forall b. exp b -> m b) -> Program (* -> *, k) i ((,) (* -> *) k exp fs) a -> m a
- type Param1 k a = (,) k * a Param0
- type Param2 k k1 a b = (,) k1 (k, *) a (Param1 k b)
- type Param3 k k1 k2 a b c = (,) k2 (k1, (k, *)) a (Param2 k k1 b c)
- data RefCMD fs a
- data ArrCMD fs a
- data ControlCMD fs a
- data PtrCMD fs a
- data FileCMD fs a
- data C_CMD fs a
- data (k :+: k1) h1 h2 fs a :: forall k k1. (k1 -> k -> *) -> (k1 -> k -> *) -> k1 -> k -> *
- class (k :<: k1) sub sup
- class FreeExp exp where
- type FreePred exp :: * -> Constraint
- class FreeExp exp => EvalExp exp
- class FreeExp exp => CompExp exp
- module Data.Int
- module Data.Word
- module Language.Embedded.Imperative.Frontend.General
- module Language.Embedded.Imperative.Frontend
Program monad
module Control.Monad
data ProgramT k instr fs m a :: forall k. ((* -> *, k) -> * -> *) -> k -> (* -> *) -> * -> * #
Representation of programs parameterized by the primitive instructions (transformer version)
MonadTrans (ProgramT k instr fs) | |
Monad m => Monad (ProgramT k instr fs m) | |
Monad m => Functor (ProgramT k instr fs m) | |
Monad m => Applicative (ProgramT k instr fs m) | |
((:<:) * (* -> *, (* -> *, (* -> Constraint, *))) (FileCMD (* -> *)) instr, (~) * a ()) => PrintfType (ProgramT (* -> *, (* -> Constraint, *)) instr (Param2 (* -> Constraint) (* -> *) exp pred) m a) Source # | |
type PrintfExp (ProgramT (* -> *, (* -> Constraint, *)) instr (Param2 (* -> Constraint) (* -> *) exp pred) m a) Source # | |
type Program k instr fs = ProgramT k instr fs Identity #
Representation of programs parameterized by the primitive instructions
:: (Interp * k i m fs, HFunctor * * k i, Monad m) | |
=> (forall b. n b -> m b) | Interpretation of the underlying monad |
-> ProgramT k i fs n a | |
-> m a |
Interpret a program in a monad. The interpretation of instructions is
provided by the Interp
class.
interpret :: (Interp * k i m fs, HFunctor * * k i, Monad m) => Program k i fs a -> m a #
Interpret a program in a monad. The interpretation of instructions is
provided by the Interp
class.
:: (InterpBi * k i m fs, HBifunctor * * k i, Functor m, Monad m, Monad n) | |
=> (forall b. exp b -> m b) | Interpretation of the |
-> (forall b. n b -> m b) | Interpretation of the underlying monad |
-> ProgramT (* -> *, k) i ((,) (* -> *) k exp fs) n a | |
-> m a |
Interpret a program in a monad. The interpretation of instructions is
provided by the InterpBi
class.
:: (InterpBi * k i m fs, HBifunctor * * k i, Functor m, Monad m) | |
=> (forall b. exp b -> m b) | Interpretation of the |
-> Program (* -> *, k) i ((,) (* -> *) k exp fs) a | |
-> m a |
Interpret a program in a monad. The interpretation of instructions is
provided by the InterpBi
class.
Imperative instructions
Commands for mutable references
HFunctor * k1 (* -> *, (* -> Constraint, *)) (RefCMD (k1 -> *)) Source # | |
HBifunctor * * (* -> Constraint, *) (RefCMD (* -> *)) Source # | |
(:<:) * (* -> *, (* -> *, (* -> Constraint, *))) (RefCMD (* -> *)) instr => Reexpressible * (* -> Constraint, *) (RefCMD (* -> *)) instr env Source # | |
InterpBi * (* -> Constraint, *) (RefCMD (* -> *)) IO (Param1 (* -> Constraint) pred) Source # | |
DryInterp (* -> *, (* -> Constraint, *)) (RefCMD (* -> *)) Source # | |
Commands for mutable arrays
HFunctor * k1 (* -> *, (* -> Constraint, *)) (ArrCMD (k1 -> *)) Source # | |
HBifunctor * * (* -> Constraint, *) (ArrCMD (* -> *)) Source # | |
(:<:) * (* -> *, (* -> *, (* -> Constraint, *))) (ArrCMD (* -> *)) instr => Reexpressible * (* -> Constraint, *) (ArrCMD (* -> *)) instr env Source # | |
InterpBi * (* -> Constraint, *) (ArrCMD (* -> *)) IO (Param1 (* -> Constraint) pred) Source # | |
DryInterp (* -> *, (* -> Constraint, *)) (ArrCMD (* -> *)) Source # | |
data ControlCMD fs a Source #
HFunctor * * (* -> *, (* -> Constraint, *)) ControlCMD Source # | |
HBifunctor * * (* -> Constraint, *) ControlCMD Source # | |
(:<:) * (* -> *, (* -> *, (* -> Constraint, *))) ControlCMD instr => Reexpressible * (* -> Constraint, *) ControlCMD instr env Source # | |
InterpBi * (* -> Constraint, *) ControlCMD IO (Param1 (* -> Constraint) pred) Source # | |
DryInterp (* -> *, (* -> Constraint, *)) ControlCMD Source # | |
(:<:) * (* -> *, (k -> *, (k1, *))) (PtrCMD (* -> *) (k -> *) k1) instr => Reexpressible k (k1, *) (PtrCMD (* -> *) (k -> *) k1) instr env Source # | |
HFunctor * k1 (k2, (k, *)) (PtrCMD (k1 -> *) k2 k) Source # | |
HBifunctor * k1 (k, *) (PtrCMD (* -> *) (k1 -> *) k) Source # | |
InterpBi * (k, *) (PtrCMD (* -> *) (* -> *) k) IO (Param1 k pred) Source # | |
DryInterp (k1, (k, *)) (PtrCMD (* -> *) k1 k) Source # | |
HFunctor * k1 (* -> *, (* -> Constraint, *)) (FileCMD (k1 -> *)) Source # | |
HBifunctor * * (* -> Constraint, *) (FileCMD (* -> *)) Source # | |
(:<:) * (* -> *, (* -> *, (* -> Constraint, *))) (FileCMD (* -> *)) instr => Reexpressible * (* -> Constraint, *) (FileCMD (* -> *)) instr env Source # | |
InterpBi * (* -> Constraint, *) (FileCMD (* -> *)) IO (Param1 (* -> Constraint) pred) Source # | |
DryInterp (* -> *, (* -> Constraint, *)) (FileCMD (* -> *)) Source # | |
HFunctor * * (* -> *, (* -> Constraint, *)) C_CMD Source # | |
HBifunctor * * (* -> Constraint, *) C_CMD Source # | |
(:<:) * (* -> *, (* -> *, (* -> Constraint, *))) C_CMD instr => Reexpressible * (* -> Constraint, *) C_CMD instr env Source # | |
InterpBi * (* -> Constraint, *) C_CMD IO (Param1 (* -> Constraint) pred) Source # | |
DryInterp (* -> *, (* -> Constraint, *)) C_CMD Source # | |
Composing instruction sets
data (k :+: k1) h1 h2 fs a :: forall k k1. (k1 -> k -> *) -> (k1 -> k -> *) -> k1 -> k -> * infixr 9 #
Coproducts
(:<:) k k1 f ((:+:) k k1 f g) | |
(:<:) k k1 f h => (:<:) k k1 f ((:+:) k k1 g h) | |
(HFunctor k k1 k2 h1, HFunctor k k1 k2 h2) => HFunctor k k1 k2 ((:+:) k (k1 -> *, k2) h1 h2) | |
(HBifunctor k k1 k2 h1, HBifunctor k k1 k2 h2) => HBifunctor k k1 k2 ((:+:) k (* -> *, (k1 -> *, k2)) h1 h2) | |
(Interp k k1 i1 m fs, Interp k k1 i2 m fs) => Interp k k1 ((:+:) k (k -> *, k1) i1 i2) m fs | |
(InterpBi k k1 i1 m fs, InterpBi k k1 i2 m fs) => InterpBi k k1 ((:+:) k (k -> *, (k -> *, k1)) i1 i2) m fs | |
(Reexpressible k k1 i1 instr env, Reexpressible k k1 i2 instr env) => Reexpressible k k1 ((:+:) * (* -> *, (k -> *, k1)) i1 i2) instr env | |
(DryInterp k i1, DryInterp k i2) => DryInterp k ((:+:) * (* -> *, k) i1 i2) Source # | |
(Functor (h2 fs), Functor (h1 fs)) => Functor ((:+:) * k h1 h2 fs) | |
A constraint f
expresses that the signature :<:
gf
is subsumed by
g
, i.e. f
can be used to construct elements in g
.
Interface for expression types
Expressions that support injection of constants and named variables
type FreePred exp :: * -> Constraint Source #
Constraint on the types of constants and variables in an expression language
Front end
module Data.Int
module Data.Word