úÎNìHóf      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcde (c) Hanzhong Xu, Meng Meng 2016, MIT Licensehanzh.xu@gmail.com experimentalportableSafeZ type, there are 4 different events: event a, no event, error event string and exit event.‰ is the type of the state machine with hidden or no storage. It is the same type with Circuit a b = Circuit (a -> Circuit a b, b)´ is a type representing a state machine. (TF s a b): initial state(transition function), s: initial storage SM storage input output = SM (TF storage input output) storage.STF is the type of simple transition function.  p is a type representing a transition function. s: storage, a: input, b: output Let's explain more about  ÿÞ. When a state gets an input a, it should do three things base on the storage and input: find the next state, update storage and output b. That's why it looks like this: (storage -> a -> (SM newState newStorage, b)) type TF storage input output = (storage -> input -> (SM storage input output, output)) Also, it is an instance of Arrow, it represents a machine without initial storage. composing two TF represents that two SM shares the same storage 'It is the same with the SM constructor.)build a simple SM which have only one TF.        (c) Hanzhong Xu, Meng Meng 2016, MIT Licensehanzh.xu@gmail.com experimentalportableSafe (c) Hanzhong Xu, Meng Meng 2016, MIT Licensehanzh.xu@gmail.com experimentalportableSafe  !"# #"!   !"#!(c) Hanzhong Xu, Meng Meng 2016,  MIT License hanzh.xu@gmail.com  experimental  portable Safe$³ type, there are 4 different events: event a, no event, error event string and exit event. data Event a = Event a | NoEvent | ErrEvent String | ExitEvent deriving (Show, Eq, Ord)extract [a] from [Event a]$%&'($$$%&'( (c) Hanzhong Xu, Meng Meng 2016, MIT Licensehanzh.xu@gmail.com experimentalportableSafe)ÿSource There are two kinds of source. First one is using the output of `SM s a a` as its input, then it becomes a perpetual motion, :) Second one is a SM which ignore its input, and output something based on its storage. The second one is easier to understand and use.‰build a source, for example: buildSrc $ foldlDelaySM (const (+1)) 0 [0..] buildSrc $ foldlDelaySM (+) 1 [1, 2, 4, 8, ...]*âbuild a simple source, which ignore the inputs fibsSM :: SM (Int, Int) () Int fibsSM = simpleSM ((a, b) () -> ((b, a+b), a)) (0, 1) take 10 $ simpleSrc fibsSM [0,1,1,2,3, ...]simpleSrc :: SM s () a -> [a]+&build a SM which just output its input, build a SM which always return b-Ddelay the input with given value. delaySM = foldlDelaySM (const id).build a SM from a function/the same with foldl0;the difference from foldlSM is it output the storage first.1habsorb a function. absorbR sm f = absorbRSM sm (arrSM f) absorbL f sm = absorbLSM (arrSM f) sm7'compose two SM and merge their storage.8Right-to-left composition9Left-to-right compositionG\converts SM a b -> SM [a] [b], it is very useful to compose SM a [b] and SM b c to SM a [c].Jrun SM a b with a.K†execute SM a b with input [a]. Also, it is the map function for SM, perhaps, We should define our own Functor class, the SMFunctor!LfmapSM f sm = sm >>> arr f%)*+,-./0123456789:;<=>?@ABCDEFGHIJKLM$)*+,-./0123456789:;<=>?@ABCDEFGHIJKL%)*+,-./0123456789:;<=>?@ABCDEFGHIJKML%)*+,-./0123456789:;<=>?@ABCDEFGHIJKLM 314151618191>3?3D2E2 (c) Hanzhong Xu, Meng Meng 2016, MIT Licensehanzh.xu@gmail.com experimentalportableSafe9;Nthe same constructor with newSMO"the same constructor with simpleSMP1hide the Storage type in the transition function.f)absorb the right SM and hide its storage.g(absorb the left SM and hide its storage.NOPfghijklmnopqrstQRSTUNOPNOPNOPfghijklmnopqrstQRSTU (c) Hanzhong Xu, Meng Meng 2016, MIT Licensehanzh.xu@gmail.com experimentalportableSafeV,transform `SM t (s, a) (s, b)` to `TF s a b`VWXYZ[\]^_`abcde VWXYZ[\]^_`VeWXdYZc[\]^b_a`VWXYZ[\]^_`abcde!(c) Hanzhong Xu, Meng Meng 2016,  MIT License hanzh.xu@gmail.com  experimental  portable Safe3 )*+,-./03456789:;>?@ADEFGIJKNOPV3 V  NOP)*,+-./07983465:;>?@ADEFGIJKu       !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{#AFSM-0.1.3.0-EspC8rUhRJAI7cJQ259dzaControl.AFSM.CoreTypeControl.AFSM.UtilControl.AFSM.SMFunctorControl.AFSM.EventControl.AFSM.CoreControl.AFSM.SMHControl.AFSM.TF Control.AFSMEventNoEventErrEvent ExitEventSMHSMSTFTFtfstnewSMsimpleSM$fShowSM $fShowEvent $fEqEvent $fOrdEvent f1template f2templateabsorbmerge SMFunctorsmexecsmfmapsmexecSM smexecSMAbindSM>>>=$fSMFunctorCompose$fSMFunctor(,)$fSMFunctorEither$fSMFunctor(->)$fSMFunctorMaybe $fSMFunctor[] extractEvents$fSMFunctorEvent $fMonadEvent$fApplicativeEvent$fFunctorEventbuildSrc simpleSrcidSMconstSMdelaySMarrSMfoldlSM foldlDelaySMabsorbRabsorbL^>>>>>>^<<<^^<<< composeSM<<<<>>>>firstSMsecondSM productSMfanoutSM****&&&&leftSMrightSMsumSMfaninSM++++||||loopSMexecSMjoinSMconcatSMstepexecfmapSM $fFunctorSMnewSMH simpleSMH hideStorage $fArrowLoopSM$fArrowApplySM$fArrowChoiceSM $fArrowSM$fCategoryTYPESM transSM2TFidTF composeTFarrTFfirstTFleftTFrightTFsumTFfaninTFappTFloopTF $fArrowLoopTF$fArrowApplyTF$fArrowChoiceTF $fArrowTF$fCategoryTYPETF absorbRSM absorbLSMidSMH composeSMHarrSMHfirstSMH secondSMH productSMH fanoutSMHleftSMHrightSMHsumSMHfaninSMHappSMloopSMH