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

| by Abel Avram Follow 5 Followers on Jun 21, 2013. Estimated reading time: 1 minute |

A note to our readers: You asked so we have developed a set of features that allow you to reduce the noise: you can get email and web notifications for topics you are interested in. Learn more about our new features.

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:


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

Rate this Article

Adoption Stage

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


Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you