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 instr fs m a :: ((,) (* -> *) k -> * -> *) -> k -> (* -> *) -> * -> *
- type Program 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 a = (,) k * a Param0
- type Param2 a b = (,) k ((,) k1 *) a (Param1 k1 b)
- type Param3 a b c = (,) k ((,) k1 ((,) k2 *)) a (Param2 k1 k2 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 (h1 :+: h2) fs a :: (k -> k1 -> *) -> (k -> k1 -> *) -> k -> k1 -> *
- class sub :<: sup
- class FreeExp exp where
- type VarPred 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 instr fs m a :: ((,) (* -> *) 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) = exp Source |
type Program instr fs = ProgramT k instr fs Identity
Representation of programs parameterized by the primitive instructions
:: forall (i :: (,) (* -> *) k -> * -> *) (fs :: k) (n :: * -> *) (m :: * -> *). (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.
:: forall (i :: (,) (* -> *) ((,) (* -> *) k) -> * -> *) (exp :: * -> *) (fs :: k) (n :: * -> *) (m :: * -> *). (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.
:: forall (i :: (,) (* -> *) ((,) (* -> *) k) -> * -> *) (exp :: * -> *) (fs :: k) (m :: * -> *). (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 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 |
Commands for mutable arrays
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 |
data ControlCMD fs a Source
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 |
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 |
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 |
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 |
Composing instruction sets
data (h1 :+: h2) fs a :: (k -> k1 -> *) -> (k -> k1 -> *) -> k -> k1 -> * 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 -> *) k2) k1 h1 h2) | |
(HBifunctor k k1 k2 h1, HBifunctor k k1 k2 h2) => HBifunctor k k1 k2 ((:+:) ((,) (* -> *) ((,) (k1 -> *) k2)) k h1 h2) | |
(Reexpressible k k1 i1 instr, Reexpressible k k1 i2 instr) => Reexpressible k k1 ((:+:) ((,) (* -> *) ((,) (k -> *) k1)) * i1 i2) instr | |
(Interp k k1 i1 m fs, Interp k k1 i2 m fs) => Interp k k1 ((:+:) ((,) (k1 -> *) k) k1 i1 i2) m fs | |
(InterpBi k k1 i1 m fs, InterpBi k k1 i2 m fs) => InterpBi k k1 ((:+:) ((,) (k1 -> *) ((,) (k1 -> *) k)) k1 i1 i2) m fs | |
(DryInterp k i1, DryInterp k i2) => DryInterp k ((:+:) ((,) (* -> *) k) * i1 i2) Source | |
(Functor (h1 fs), Functor (h2 fs)) => Functor ((:+:) k * h1 h2 fs) |
class sub :<: sup
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 values and named variables
type VarPred exp :: * -> Constraint Source
Constraint on the types of values and variables in an expression language
Front end
module Data.Int
module Data.Word