Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

Some guy insists "true FRP principle" as follows:


  1. A (FRP) library user will describe a mapping f as

    Current TimeStamp => State

by referential transparent function or stream.

  1. A system applies the System TimeStamp(t=0,1,2...) to the f

  2. Accordingly, A system obtains State: f(0),f(1),f(2),....

This should be the "true FRP basic principle".


The guy also shown the following code as a "proof of the concept".

The original source is from http://anond.hatelabo.jp/20160518122300

(Haskell ReactiveBanana)


ReactiveBananaDrawingCanvas.hs
import Data.Monoid (mconcat)
import Reactive.Banana (accumB)
import Graphics.Gloss.Interface.Pure.Game
import Graphics.Gloss.Interface.FRP.ReactiveBanana (playBanana)

main = playBanana disp colour freq gen
 where
  disp = (InWindow "Drawing Canvas" (400, 400) (40, 40))
  colour = white
  freq = 100
  gen deltaTime = return . fmap draw . accumB (False,[],[]) . fmap eTrans
  draw (_, path, paths) = mconcat $ map line $ path:paths
  eTrans (EventKey (MouseButton LeftButton) Down _ _ ) (_, path, paths) = (True, path, paths)
  eTrans (EventKey (MouseButton LeftButton) Up _ _ ) (_, path, paths) = (False, [], path:paths)
  eTrans (EventMotion pos) (True, path, paths) = (True, pos:path, paths)
  eTrans _ world = world

https://hackage.haskell.org/package/gloss-banana-0.1.0.4/docs/src/Graphics-Gloss-Interface-FRP-ReactiveBanana.html

  playIO display colour frequency ()
    (\      _ → readIORef pictureref)
    (\ ev   _ → () <$ event ev)
    (\ time _ → () <$ tick time)

https://hackage.haskell.org/package/gloss-1.10.1.1/docs/src/Graphics-Gloss-Interface-IO-Game.html

playIO  display backColor simResolution
        worldStart worldToPicture worldHandleEvent worldAdvance

 = playWithBackendIO defaultBackendState
        display backColor simResolution
        worldStart worldToPicture worldHandleEvent worldAdvance
        False

https://hackage.haskell.org/package/gloss-1.10.1.1/docs/src/Graphics-Gloss-Internals-Interface-Game.html

        , Callback.Idle         (callback_simulate_idle 
                                        stateSR animateSR (readIORef viewSR)
                                        worldSR (\_ -> worldAdvance)
                                        singleStepTime)

I don't get it. The code presented as a "proof of the concept" is nothing to do with the "true FRP principle" that he claims, I think.

I am not a user of ReactiveBanana, so I'd like to double-check by people here. Thanks.

share|improve this question
    
What exactly is your question? StackOverflow is not a discussion forum. – Bergi May 18 at 8:17
2  
The question is clear: Does the code presented as a "proof of the concept" corresponds to the "true FRP principle" that he claims. True or False – Ken OKABE May 18 at 8:21

If that is your question (though I don't think it is clear from your original post), the answer is clear: True.

As to (1), the library user provides the gen function (passed to playBanana) which returns a value of Behavior t Picture type wrapped in Moment t monad, and this Behavior t Picture is exactly what you wrote as Current TimeStamp => State. (2) and (3) are done by reactive-banana library with respect to this Behavior t Picture value.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.