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

  • Home
  • SEARCH
  • 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 7009841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:54:50+00:00 2026-05-27T21:54:50+00:00

I’m trying to understand how this functional reactive programming works, and I have run

  • 0

I’m trying to understand how this functional reactive programming works, and I have run into a problem. I am trying to create a boid simulation, but I’m starting out slowly, and I have for now defined a boid as a function taking a starting position and creating a signal function from a position to a position, where the input is the point it is moving towards and the output is the current position:

type Position2 = Vector2 Float

boid :: Position2 -> SF Position2 Position2
boid s = loop (arr (uncurry seek) >>> integral >>> arr (^+^ s) >>> arr dup)

the seek function takes two inputs (because of the loop). The current position and the target position. Then it just creates a vector pointing from the current position towards the target position with a magnitude of 50 i.e. the velocity. Then the velocity is integrated and the starting position is added. In the end the signal is split into two, so one can become the output and the other can loop back into the seek function.

Now i can define boids like this:

aBoid = constant (vector2 500 500) >>> (boid (vector2 600 60))
bBoid = aBoid >>> (boid (vector2 3 4))

Here aBoid seeks towards the point (500, 500) and bBoid seeks towards aBoid.

My problem is, when i want the two boids to seek toward each other. When i do this:

aBoid = bBoid >>> (boid (vector2 600 60))
bBoid = aBoid >>> (boid (vector2 3 4))

The program just prints: ProgramName: <<loop>> which I assume means that it goes into an endless loop.

I have also tried to use the par function like this:

sim :: SF a [Position2]
sim = loop (arr snd >>> par route [boid (vector2 10 10), boid (vector2 100 100)] >>> arr dup)

here the route function just maps the output of each boid to the input of another one (like zip, but with an offset of 1)

This also gives the <<loop>> message.

I would think that having objects depend on the state of each other should be a pretty common problem when dealing with reactive systems, so I hope there is some elegant solution.

I should add that I find this FRP thing very hard and often confusing, so I’m not really sure if i even make sense at all 😉

  • 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-27T21:54:51+00:00Added an answer on May 27, 2026 at 9:54 pm

    So with a little help from ehird i came up with something that works.

    The code is as follows(here using 3 boids instead of 2):

    sim :: SF a [Position2]
    sim = loopPre [zeroVector, zeroVector, zeroVector] (
        arr snd >>>
        par route [boid (vector2 10 10), boid (vector2 100 400), boid (vector2 500 500)] >>>
        arr dup)
    

    Here the route function works the same as the one i described in the question.

    By using loopPre instead of loop i can give each boid a starting position, which solves the problem. I think the reason ehird’s solution did not work, was that some plumbing is required when running several signal functions in parallel, which the par function takes care of.

    An answer from someone who is 100% sure whats going on would be appreciated 🙂

    Edit

    This implementation of sim is a little prettier:

    sim :: Int -> SF a [Position2]
    sim num = loopPre (take num (repeat zeroVector)) (
        arr snd >>>
        par route (randomBoids num) >>>
        arr dup)
    

    Where randomBoids num generates num random boids.

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

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to create an if statement in PHP that prevents a single post

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.