.../programatica/examples/ChannelSeparation/Monadic/
runProtected
onePacket :: Algs->Packet->StateM ChipState (Maybe Packet)
onePacket :: Algs->Packet->StateM ChipState Packet
Memory
implements finite maps using functions
Regs
and Algs
use a finite map implementation
based on lists
Alg
RegFile
, Reg
Addr
,
Word
,
Memory
RegFile
, Word
Memory
, Addr
, and related functions
Alg
, Code
instance Eq k => FiniteMap ((->) k) k where ...
Alg
:
type Alg = Nat -> RegFile -> StateM Memory RegFile
doPacket :: Alg -> Data -> RegFile -> StateM Memory (Data,RegFile)
RegFile
: none
Reg
: none
Word
: none
Channel
: none
StateM
: none
(except what you get for free from its implementation)
type Algs = Channel -> Alg
type ChipState = (Memory,Regs)
type Packet = (Channel,Data)
type Data = [Word]
type StateM s a = s -> (a,s)
chip :: Algs -> ChipState -> [Packet] -> StateM ChipState [Packet]
onePacket :: Algs -> Channel -> Data -> StateM ChipState Packet
ps = []
ps = (ch',ws):ps'
ch' == ch
: the equation reduces to
{p1:pick ch (chip algs state1' ps')}
=== {p2:chip algs state2' (pick ch ps')}
ch' /= ch
: the equation reduces to
{pick ch (chip algs state1' ps')}
=== {chip algs state2 (pick ch ps')}
Lines | Words | Chars | File name |
---|---|---|---|
81 | 357 | 3202 | ChipModel.alfa |
46 | 171 | 1244 | FiniteMaps2.alfa |
30 | 123 | 882 | Memories.alfa |
93 | 375 | 2316 | Monads.alfa |
51 | 252 | 1457 | State.alfa |
451 | 1225 | 22077 | ChipModelProps5.alfa |
752 | 2503 | 31178 | total |
runProtected
and algorithms that can fail