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 8298361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:44:41+00:00 2026-06-08T15:44:41+00:00

I’m trying to implement callbacks in opa, so when a variable gets updated on

  • 0

I’m trying to implement callbacks in opa, so when a variable gets updated on the server side, clients get that updated value immediately.

I know I could do it with a network:

Network.add_callback(update_function, room)

however, as a learning exercise I would like to implement that feature myself.

My first thought was to create a list of void->void functions list(void->void), which is where I encounter my first problem in the lack of mutable state and variables. So I can’t add any callback functions to the created list.

This leads me to my first question: How do I work with no mutable state? I don’t consider myself new to functional programming, but normally I would just reassign a variable

i.e.

x = ['a','b','c']
function addVal(val){
    x = List.add(val,x)
}

But this doesn’t seem to be legal in opa.

How is it possible to work without variables or mutable data structures? I don’t see how any dynamic content can be implemented without mutable state.

I decided to try to get around the issue by storing my list of callback functions in a database:

database callbacks{
  list(void -> void) functions
}

but I get the error

Elements of type void -> void cannot be stored in the database

Which leads me to my second question:

Are there any better resources for opa available than doc.opalang.org? I haven’t been able to find any information on the types that are allowed in a database.

So in summary:

  1. How do I build a program that actually does anything without the use of mutable state or variables?
  2. What types are allowed in opa databases?
  3. Are there any useful resources for opa other than doc.opalang.org?
  • 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-06-08T15:44:43+00:00Added an answer on June 8, 2026 at 3:44 pm

    1) Opa is a functional language,
    Thus indeed the first example is not legal in Opa.

    x = ['a', 'b', 'c']
    

    Doesn’t declare a variable x, but a binding between the ident x and the value ['a', 'b', 'c'].

    Even if Opa is a functional language, you have mutable as you see on the OpaDoc.
    But as you known mutable value are not thread safe, i.e. you can be preempted beetwen get and set, implies your sate is inconsistent.

    So to resolve this problem you can use Session. Basically a session is a state and a message handler. The session handler is thread safely executed to update the session state. Another advantage a session can be serialized and manipulates seamlessly by any system entity.

    Your example can be written :

    // A channel which can receive add message 
    channel({string add}) s = Session.make(['a', 'b', 'c'], 
          function(oldstate, message){
            match(message){
              case {add : value} : {set : List.add(value, oldstate)} //setting the new state
              .... // other message
            }
          }
        )
    
    function addVal(value){
      Session.send(s, {add : value}
    }
    

    2) You can store only purely data structure in the database.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
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
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:

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.