The topic of this article may not meet Wikipedia's notability guidelines for products and services. (June 2011) |
Opa is a programming language for web application development release under a dual license: Gnu Affero GPL and a private license. The language was first officially presented at the OWASP conference in 2010, and the source code was released on GitHub in June 2011.
Opa | |
---|---|
Paradigm | multi-paradigm: functional, imperative |
First appeared | 2011 |
Typing discipline | strong, static |
OS | Linux, Mac OS X |
License | AGPL |
Filename extensions | .opa, .opp |
Website | opalang.org |
Influenced by | |
Ocaml |
Philosophy
Opa is a single programming language for web applications, both for the client and server code.
Example source code
/**
* The type of messages sent by a client to the chatroom
*/
type message = {author: string /**The name of the author (arbitrary string)*/
; text: string /**Content entered by the user*/}
/**
* The chatroom.
*/
@publish room = Network.cloud("room"): Network.network(message)
/**
* Update the user interface in reaction to reception of a message.
*
* This function is meant to be registered with [room] as a callback.
* Its sole role is to display the new message in [#conversation].
*
* @param x The message received from the chatroom
*/
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 text to the [room].
*
* Read the contents of [#entry], clear these contents and send the message to [room].
*
* @param author The name of the author. Will be included in the message broadcasted.
*/
broadcast(author) =
do Network.broadcast({~author text=Dom.get_value(#entry)}, room)
Dom.clear_value(#entry)
/**
* Build the user interface for a client.
*
* Pick a random author name which will be used throughout the chat.
*
* @return The user interface, ready to be sent by the server to the client on connection.
*/
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" onclick={_ -> broadcast(author)}>Post</div>
</div>
/**
* Main entry point.
*
* Construct an application called "Chat" (users will see the name in the title bar),
* embedding statically the contents of directory "resources", using the global stylesheet
* "resources/css.css" and the user interface defined in [start].
*/
server = Server.one_page_bundle("Chat",
[@static_resource_directory("resources")],
["resources/css.css"], start)