Opa

Opa is a programming language for applications and services usable web licensed Affero GPL or under private license.

Philosophy

Opa is a technology for developing distributed Web applications. It is a new programming language strongly coupled to a standard Web library that fulfills all functions: from web application server to database server.

In a nutshell, Opa does not depend on current server stacks, such as Apache plus PHP plus MySQL plus Symfony . An Opa source code is compiled into a standalone binary of the service, which is limited to a bare GNU / Linux distribution (even MiniLinux ) for execution.

Opa is specially designed for the Web and specifies all aspects of the application:

  • The client code and the server code are written in Opa: the compiler automatically determines the client and server parts (annotations exist to force it), translates the client code into JavaScript and automates the exchanges between client and server;
  • The database structure and queries are also written in Opa: again, the compiler analyzes queries during compilation and generates the data access code.

Code Listing

The example below is the complete code of a minimal webchat in Opa.

/ **
* The type of messages exchanged on the chatroom
* /
type message =
 { author : string // The name of the author
 ; Text : string } // The text of the message
/ **
* The main "object": the message room
* /
@ publish room = Network . Cloud ( "room" ) : Network . Network ( message )
/ **
* Update user interface when new message arrives
*
* @param x The message
* /
user_update ( x : message ) =
 line = < div class = "line" >
 < Div class = "user" > { x . Author } : </ div >
 < div class = "message" > { x . Text } < / Div >
 </ div >
 do Dom . Transform ([ # conversation + <- line ])
 Dom . Scroll_to_bottom ( # conversation )
/ **
* Broadcast a message on the room
*
* Read the contents of [#entry], send the message to [room] and then delete [#entry].
*
* @param author
* /
broadcast ( author ) =
 do Network . Broadcast ({ ~ author text = Dom . Get_value ( # entry )}, room )
 Dom . Clear_value ( # entry )
/ **
* Constructs the client interface
*
* Randomly selects an author name to be used in chat
*
* @return The user interface, sent by the server when connecting a client.
* /
Start () =
 author = Random . string ( 8 )
 < div id = # header > < div id = # logo > </ div > </ div >
 < Div id = # conversation onready = { _ -> Network . add_callback ( user_update , room )} > </ div >
 < div id = # footer >
 < input id = # entry onnewline = { _ -> Broadcast ( author )} />
 < div class = "button"
/ **
* Main program
*
* Builds a "Chat" application (will also be the page title),
* statically includes the resources directory containing CSS and
*
style images and calls the [start] That a client connects. * /
Server = server . One_page_bundle ( "chat" ,
 [ @ static_resource_directory ( "resources" )],
 [ "resources / css.css" ], start )