haskell - Why and how the Continuation Monad solves the callback hell? In other words : Is RX or FRP = Continuation Monad ? IF not =, what is the difference? -
here , here said continuation monad solves callback hell.
rx , frp solve callback hell.
if these 3 tools solve callback hell following question arises:
in erik's video said rx=continuation monad. true? if yes, show mapping?
if rx not = cont. monad difference between rx , continuation monad?
similarly, difference between frp , continuation monad ?
in other words, assuming reader knows frp or rx is, how can reader understand continuation monad ?
is possible/easy understand continuation monad comparing rx or frp ?
i'm not familiar rx, regarding frp , continuation monad, they're fundamentally different concepts.
functional reactive programming solution problem of working time-dependent values , events. events, can solve callback problem sequencing computations in such way when 1 finishes, event sent , triggers next one. callbacks don't care time, want sequence computations in specific way, unless whole program based on frp, it's not optimal solution.
the continuation monad has nothing time @ all. it's abstract concept of computations can (loosely speaking) take "snapshots" of current evaluation sequence , use them "jump" snapshots arbitrarily. allows create complex control structures such loops , coroutines. have @ definition of continuation monad:
newtype cont r = cont { runcont :: (a -> r) -> r}
this function callback! it's function accepts continuation (callback) continue computation after a
produced. if have several functions take continuations,
f1 :: (int -> r) -> r f2 :: int -> (char -> c) -> c f3 :: char -> (string -> d) -> d
their composition becomes messy:
comp :: string comp = f1 (\a -> f2 (\b -> f3 b id))
using continuations, becomes straightforward, need wrap them in cont
, sequence them using monadic bind operaiton >>=
:
import control.monad.cont comp' :: string comp' = runcont (cont f1 >>= cont . f2 >>= cont . f3) id
so continuations direct solution callback problem.
Comments
Post a Comment