Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 964659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:51:56+00:00 2026-05-16T01:51:56+00:00

I am a student currently learning about Functional Reactive paradigm using F#. It’s radically

  • 0

I am a student currently learning about Functional Reactive paradigm using F#. It’s radically new viewpoint for me. Yesterday I learned about creating a simple ping-pong game using this paradigm. The idea I grasp so far is : we think values as functions of time. On its pure form, it’s stateless. However, I need to remember the position of the ball (or state). So I always pass the current position of the ball as the parameter of the global function.

If we talk about slight more complex games, like Space Invaders, we have a lot of states (aliens’ position, aliens’ current HP, number of remaining bombs, etc)

Is there an elegant/best way to tackle this problem? Do we always store states on the top level? Do all current states should be given as the additional input argument of the global function?

Can anybody explain this using simple sample on F#?
Thanks a lot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:51:56+00:00Added an answer on May 16, 2026 at 1:51 am

    There’s more than one way to do FRP, and it’s an active area of research. What’s best can depend a lot on the details of how things interact with each other, and new and better techniques may appear in the future.

    Broadly the idea is to have behaviours that are functions of time in place of ordinary values (as you said). Behaviours can be defined in terms of other behaviours, and can be defined to swap between other behaviours when particular events occur.

    In your example, you generally wouldn’t need to remember the position of the ball via arguments (but for some kinds of FRP you might do). Instead you can just have a behaviour:
    ballPos : time -> (float * float)
    This might have global scope, or for a larger program it may be better to have a local scope with all uses of it in that scope.

    As things get more complicated, you’ll have behaviours defined in increasingly complex ways, depend on other behaviours and events – including recursive dependencies which are handled differently in different FRP frameworks. In F# for recursive dependencies I’d expect you’d need a let rec including all involved behaviours. These can still be organised into structures though – at the top-level you might have:

    type alienInfo =  { pos : float*float; hp : float }
    type playerInfo = { pos : float*float; bombs : int } 
    let rec aliens : time -> alienInfo array =             // You might want laziness here.
        let behaviours = [| for n in 1..numAliens -> 
                            (alienPos player n, alienHP player n) |]
        fun t -> [| for (posBeh, hpBeh) in behaviours -> 
                    {pos=posBeh t; hp=hpBeh t} |]          // You might want laziness here.
    and player : time -> playerInfo  = fun t ->
        { pos=playerPos aliens t; bombs=playerBombs aliens t}
    

    And then the behaviours for alienPos, alienHP can be defined, with dependencies on the player, and playerPos, playerBombs can be defined with dependencies on aliens.

    Anyway, if you can give more details of what kind of FRP you’re using, it will be easier to give more specific advice. (And if you want advice on what kind – personally I’d recommend reading: http://conal.net/papers/push-pull-frp/push-pull-frp.pdf)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a .NET student and currently we are learning about Application Domains. We
I am a student programmer using QT to develop and application for work. Currently
I am currently a student programmer using Qt to build a GUI inteface at
I'm a computer science student. Currently we are learning the Ada programming language. The
I'm currently learning mysql, so I am very new to this, tried to find
everyone I am a student and new to .NET and specially MVC3 development. Currently
I'm currently on learning on using Dao pattern in my project. I know, one
I am a computer science student currently doing an internship. My boss has asked
Firstly I am no longer a student and currently working on a favour for
I'm currently a student and I'm studying PHP, I'm trying to make a simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.