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

Safe HaskellNone
LanguageHaskell2010

Language.Embedded.Imperative

Contents

Description

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.

Synopsis

Program monad

data ProgramT instr fs m a :: ((,) (* -> *) k -> * -> *) -> k -> (* -> *) -> * -> *

Representation of programs parameterized by the primitive instructions (transformer version)

Instances

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

interpretT

Arguments

:: 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.

interpretBiT

Arguments

:: 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 exp sub-structure

-> (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.

interpretBi

Arguments

:: 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 exp sub-structure

-> 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.

type Param1 a = (,) k * a Param0

Singleton parameter list

type Param2 a b = (,) k ((,) k1 *) a (Param1 k1 b)

Two-element parameter list

type Param3 a b c = (,) k ((,) k1 ((,) k2 *)) a (Param2 k1 k2 b c)

Three-element parameter list

Imperative instructions

data RefCMD fs a Source

Commands for mutable references

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 

data ArrCMD fs a Source

Commands for mutable arrays

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 

data ControlCMD fs a Source

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 

data PtrCMD fs a Source

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 

data FileCMD fs a Source

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 

data C_CMD fs a Source

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 

Composing instruction sets

data (h1 :+: h2) fs a :: (k -> k1 -> *) -> (k -> k1 -> *) -> k -> k1 -> * infixr 9

Coproducts

Instances

(:<:) 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 :<: g expresses that the signature f is subsumed by g, i.e. f can be used to construct elements in g.

Minimal complete definition

inj, prj

Instances

(:<:) k k1 f f 
(:<:) k k1 f ((:+:) k k1 f g) 
(:<:) k k1 f h => (:<:) k k1 f ((:+:) k k1 g h) 

Interface for expression types

class FreeExp exp Source

Expressions that support injection of values and named variables

Minimal complete definition

valExp, varExp

Associated Types

type VarPred exp :: * -> Constraint Source

Constraint on the types of values and variables in an expression language

Instances

class FreeExp exp => EvalExp exp Source

Expressions that support evaluation

Minimal complete definition

evalExp

Instances

class FreeExp exp => CompExp exp Source

General interface for compiling expressions

Minimal complete definition

compExp

Instances

Front end

module Data.Int

module Data.Word