BT
x Your opinion matters! Please fill in the InfoQ Survey about your reading habits!

FunScript: Using the Power of F# for Writing Web Apps

by Abel Avram on Jun 21, 2013 |

FunScript is an F# compiler library enabling developers to write single-page web applications in F# and running them in the browser or on the server via Node.js.

FunScript has two components: a compiler library used to convert F# code into JavaScript and a TypeScript type provider used to expose the APIs of various JavaScript libraries and the DOM as static types.

A sample “Hello, World” example written in FunScript looks like this:

[<FunScript.JS>]

module Page

 

open FunScript

open FunScript.TypeScript

type lib = Api<"lib.d.ts">

let hello () = lib.window.alert("Hello, World!")

do Runtime.Run(components=Interop.Components.all)

Each module is saved in a “.fs” file and it must be annotated with the FunScript.JS attribute. The page’s DOM is accessed via the type lib. The last line is used to start the launcher. The module is stored on a simple web server by default.

FunScript modules can be created in Visual Studio, MonoDevelop or a simple text editor. The library gets powerful because it allows the developer to interrogate the types found in various JavaScript libraries, having access to autocomplete and tooltip features. The types are provided via TypeScript, and, currently, the FunScript GitHub project contains type definitions for HTML DOM, jQuery, jQueryUI, Node.js, Google Maps, and HighCharts, which are interactive JavaScript charts. A much larger collection of JS type definitions can be found here.

Another advantage of using FunScript for web applications is the ability to use F#’s generics and asynchronous programming capabilities. Also, the developer can work with JSON data and REST APIs using F# 3.0 type providers. All of that while maintaining F#’s conciseness.

FunScript’s website contains a number of samples, including Charting World Bank data with F# and Searching The Movie Database with F#. More samples can be found on project’s GitHub page.

FunScript is an open source project licensed under Apache License 2.0

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT