úÎVçOĞm      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcde f g h i j k l  (c) Hanzhong Xu, Meng Meng 2016, MIT Licensehanzh.xu@gmail.com experimentalportableSafem2Constructor with storage, or smart constructor, :)nsimple constructormnmn (c) Hanzhong Xu, Meng Meng 2016, MIT Licensehanzh.xu@gmail.com experimentalportableSafeopqrstuvwxyz{opqrstuvwxyz{  (c) Hanzhong Xu, Meng Meng 2016, MIT Licensehanzh.xu@gmail.com experimentalportableSafe (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ÿ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 foldl%;the difference from foldlSM is it output the storage first.&habsorb a function. absorbR sm f = absorbRSM sm (arrSM f) absorbL f sm = absorbLSM (arrSM f) sm,'compose two SM and merge their storage.-Right-to-left composition.Left-to-right composition<\converts SM a b -> SM [a] [b], it is very useful to compose SM a [b] and SM b c to SM a [c].?run SM a b with a.@†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!AfmapSM f sm = sm >>> arr f% !"#$%&'()*+,-./0123456789:;<=>?@AB$ !"#$%&'()*+,-./0123456789:;<=>?@A% !"#$%&'()*+,-./0123456789:;<=>?@BA% !"#$%&'()*+,-./0123456789:;<=>?@AB (1)1*1+1-1.1334392:2 (c) Hanzhong Xu, Meng Meng 2016, MIT Licensehanzh.xu@gmail.com experimentalportableSafeC,transform `SM t (s, a) (s, b)` to `TF s a b`CDEFGHIJKLMNOPQR CDEFGHIJKLMCRDEQFGPHIJKOLNMCDEFGHIJKLMNOPQR (c) Hanzhong Xu, Meng Meng 2016, MIT Licensehanzh.xu@gmail.com experimentalportableSafe STUVWXYZ[\]^_STUVWXY STU_^]\[VWZXY STUVWXYZ[\]^_!(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]`abcd```abcd  (c) Hanzhong Xu, Meng Meng 2016, MIT Licensehanzh.xu@gmail.com experimentalportableSafe9;ethe same constructor with newSMf"the same constructor with simpleSMg1hide the Storage type in the transition function.|)absorb the right SM and hide its storage.}(absorb the left SM and hide its storage.efg|}~€‚ƒ„…†‡ˆ‰Šhijklefgefgefg|}~€‚ƒ„…†‡ˆ‰Šhijkl !(c) Hanzhong Xu, Meng Meng 2016,  MIT License hanzh.xu@gmail.com  experimental  portable Safe3  !"#$%()*+,-./034569:;<>?@CSTUefg3 STUC  efg! "#$%,.-()+*/034569:;<>?@‹    !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijkl m n o p q r s tuvwxyz{|}~€‚ƒ „ … † ‡ ˆ ‰ Š ‹ Œ ‘ ’“#AFSM-0.1.3.1-JDmtAezErILCrLOw6WkxvjData.SF.CoreType Data.SF.CoreControl.AFSM.CoreTypeControl.AFSM.UtilControl.AFSM.CoreControl.AFSM.TFControl.AFSM.SMFunctorControl.AFSM.EventControl.AFSM.SMHData.SF Control.AFSMSF $fArrowLoopSF$fArrowApplySF$fArrowChoiceSF $fArrowSF$fCategoryTYPESFEventNoEventErrEvent ExitEventSMHSMSTFTFtfstnewSMsimpleSM$fShowSM $fShowEvent $fEqEvent $fOrdEvent f1template f2templateabsorbmergebuildSrc simpleSrcidSMconstSMdelaySMarrSMfoldlSM foldlDelaySMabsorbRabsorbL^>>>>>>^<<<^^<<< composeSM<<<<>>>>firstSMsecondSM productSMfanoutSM****&&&&leftSMrightSMsumSMfaninSM++++||||loopSMexecSMjoinSMconcatSMstepexecfmapSM $fFunctorSM transSM2TFidTF composeTFarrTFfirstTFleftTFrightTFsumTFfaninTFappTFloopTF $fArrowLoopTF$fArrowApplyTF$fArrowChoiceTF $fArrowTF$fCategoryTYPETF SMFunctorsmexecsmfmapsmexecSM smexecSMAbindSM>>>=$fSMFunctorCompose$fSMFunctor(,)$fSMFunctorEither$fSMFunctor(->)$fSMFunctorMaybe $fSMFunctor[] extractEvents$fSMFunctorEvent $fMonadEvent$fApplicativeEvent$fFunctorEventnewSMH simpleSMH hideStorage $fArrowLoopSM$fArrowApplySM$fArrowChoiceSM $fArrowSM$fCategoryTYPESMnewSFsimpleSFidSF composeSFarrSFfirstSFsecondSF productSFfanoutSFleftSFrightSFsumSFfaninSFappSFloopSF absorbRSM absorbLSMidSMH composeSMHarrSMHfirstSMH secondSMH productSMH fanoutSMHleftSMHrightSMHsumSMHfaninSMHappSMloopSMH