haskell - Confused about diagrams of Yampa switches -


there diagrams of yampa switches at:

http://www.haskell.org/haskellwiki/yampa/switch

http://www.haskell.org/haskellwiki/yampa/rswitch

http://www.haskell.org/haskellwiki/yampa/kswitch

(and on).

i've found switch, 1 diagram description, easiest 1 understand. others seems hard follow similar symbols read diagrams. example, try read rswitch symbols used in switch may be:

be recursive sf fed signal of type 'in' , returns signal of type 'out'. start initial sf of same type outside switch function (the ?[cond]) square) may pass new sf via event (the type event (sf in out) @ signature) while condition satisfied (for '?' before [cond] square). in case of event, yampa use new sf instead of existing one. process recursive since '?' (can't diagram except signature of rswitch seems recursive).

and after source of rswitch, looks use switch switch same init sf recursively while t fired (according described in diagram, although don't see special t fired in source code).

in yampa arcade explains dpswitch code , example. , paper game 'frag' uses dpswitch. rswitch seems absent in these tutorial. don't know how use r- or k-serial switches, , in cases need them.

all of switch functions ways change signal function behave signal function. find yampa diagrams difficult parse, type signatures of various switches give indication how understand them. once understand type signatures, diagrams become clearer. switch basic:

switch :: sf (b, event c) -> (c -> sf b) -> sf b 

if @ type, tells does: takes sf sf , sf generator sfg. sf produces values of type (b, event c), , input signal function generator happens of type c. so, whenever sf's event occurs, sf switch result of sf generator. until event occurs, resulting sf return value of original sf.

this idea used in rswitch , kswitch variants bit differently.


rswitch : known "extrinsic switch", meaning sf switch without analysis of input or output. let's @ type signature:

rswitch :: sf b -> sf (a, event (sf b)) b 

it takes single sf takes input values of type a , outputs values of type b. rswitch creates new sf produces output b, takes additional input of type event (sf b). note event value's type matches input type. means whenever event happens, sf switch event value. however, type of sf remains sf (a, event (sf b)) b. means sf free receive additional events new sfs, influence behavior of overall sf. 1 use ai behaviors in game:

movefollowtarget :: sf targetposition velocity moveshoottarget :: sf targetposition velocity moveidle :: sf targetposition velocity  aimovement :: sf (targetposition, event (sf targetposition velocity)) velocity aimovement = rswitch moveidle  -- idle...  aimovementmanager :: sf (event (sf targetposition velocity)) aimovementmanager = ... whatever ... 

here, aimovementmanager fire event whenever movement behavior of ai needs change, , value of event sf movement should change to.


kswitch: known intrinsic switch, since contents of sf analyzed figure out proper switch should be. let's go on type signature

kswitch :: sf b -> sf (a, b) (event c) -> (sf b -> c -> sf b) -> sf b 

here, kswitch takes 3 arguments, sf, analyzer, , mapping. sf standard sf inputs of type a , outputs of type b. sf how signal behaves initially. analyzer sf takes input , output of sf , may or may not fire sort of event value has type c. if doesn't fire event, nothing happens, , sf continues behave sf. if fire event, both sf , event value passed mapping determines new sf switch to. kswitch useful when changing way systems behave based on outputs.

one example useful algorithm tcp congestion avoidance. here, @ whether or not lose network packets, , either increase or decrease speed @ request data.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -