FunScript

F# to JavaScript with type providers

// Allow access to the F# AST
[<ReflectedDefinition>]
module Sample

open FSharp.Data
open FunScript
open FunScript.TypeScript

// Access standard JavaScript libraries in a type-safe way.
// Generate strongly-typed interfaces from TypeScript 0.9.x 
// definitions files or use any of the 280+ pre-built library
// mappings (hosted on NuGet).
#r "FunScript.TypeScript.Binding.lib.dll"
#r "FunScript.TypeScript.Binding.jquery.dll"
#r "FunScript.TypeScript.Binding.highcharts.dll"

// Integrate REST APIs with F# 3.0 type providers
type WorldBank = WorldBankDataProvider<Asynchronous=true>
let data = WorldBank.GetDataContext()

// Get full type checking for external data sources!
let countries = 
  [ data.Countries.Denmark
    data.Countries.``Czech Republic``
    data.Countries.``United Kingdom``
    data.Countries.``United States`` ]

// Easily define strongly-typed Foreign Function Interfaces
// (FFIs) to access unmapped functions
[<JSEmitInlineAttribute("({0} * 1.0)")>]
let number(x : int) : float = failwith "never"

// Write asynchronous computations without callbacks
let render () = async {
  let chart = createEmpty<HighchartsOptions>()
  chart.series <- [| |]
  for country in countries do

    // Access data sets in a statically typed way
    let data = country.Indicators
    let! l = data.``School enrollment, tertiary (% gross)``

    // Add line series to the chart
    let seriesOpts = createEmpty<HighchartsSeriesOptions>()
    seriesOpts.name <- country.Name
    seriesOpts.data <- 
        [| for t, y in l -> [| number t; y |] :> obj |]

    // Use a standard library function 
    // through ...Binding.lib.dll
    chart.series.pushOverload2 seriesOpts |> ignore 
}

Contributions

FunScript is open-source and created by F# experts and active community contributors.

Help us improve FunScript!

FunScript is a lightweight F# library that lets you rapidly develop single-page applications. You can connect to external data sources and call REST APIs with intellisense, produce dashboards using JavaScript visualization libraries and write asynchronous computations easily without explicit callbacks.

Get FunScript today!

What do you get

FunScript on Channel 9

Tomas talks about type providers, the F# Data library and FunScript on Channel 9 and shows how you can easily visualize World Bank data and connect to The Movie Database.

Tomas Petricek: How F# Learned to Stop Worrying and Love the Data
Multiple items
type ReflectedDefinitionAttribute =
  inherit Attribute
  new : unit -> ReflectedDefinitionAttribute

Full name: Microsoft.FSharp.Core.ReflectedDefinitionAttribute

--------------------
new : unit -> ReflectedDefinitionAttribute
module Sample
namespace FSharp
namespace FSharp.Data
namespace FunScript
namespace FunScript.TypeScript
type WorldBank = WorldBankDataProvider<...>

Full name: Sample.WorldBank
type WorldBankDataProvider

Full name: FSharp.Data.WorldBankDataProvider


<summary>Typed representation of WorldBank data with additional configuration parameters</summary>
                        <param name='Sources'>The World Bank data sources to include, separated by semicolons. Defaults to "World Development Indicators;Global Financial Development". If an empty string is specified, includes all data sources.</param>
                        <param name='Asynchronous'>Generate asynchronous calls. Defaults to false</param>
val data : WorldBankDataProvider<...>.ServiceTypes.WorldBankDataService

Full name: Sample.data
WorldBankDataProvider<...>.GetDataContext() : WorldBankDataProvider<...>.ServiceTypes.WorldBankDataService
val countries : WorldBankDataProvider<...>.ServiceTypes.Country list

Full name: Sample.countries
property WorldBankDataProvider<...>.ServiceTypes.WorldBankDataService.Countries: WorldBankDataProvider<...>.ServiceTypes.Countries
property WorldBankDataProvider<...>.ServiceTypes.Countries.Denmark: WorldBankDataProvider<...>.ServiceTypes.Country


The data for country 'Denmark'
Multiple items
type JSEmitInlineAttribute =
  inherit Attribute
  new : emit:string -> JSEmitInlineAttribute
  member Emit : string

Full name: FunScript.JSEmitInlineAttribute

--------------------
new : emit:string -> JSEmitInlineAttribute
val number : x:int -> float

Full name: Sample.number
val x : int
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
Multiple items
val float : value:'T -> float (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.float

--------------------
type float = System.Double

Full name: Microsoft.FSharp.Core.float

--------------------
type float<'Measure> = float

Full name: Microsoft.FSharp.Core.float<_>
val failwith : message:string -> 'T

Full name: Microsoft.FSharp.Core.Operators.failwith
val render : unit -> Async<unit>

Full name: Sample.render
val async : AsyncBuilder

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.async
val chart : HighchartsOptions
val createEmpty : unit -> 'a

Full name: TypeExtensions.createEmpty
type HighchartsOptions

Full name: FunScript.TypeScript.HighchartsOptions
property HighchartsOptions.series: HighchartsSeriesOptions array
val country : WorldBankDataProvider<...>.ServiceTypes.Country
val data : WorldBankDataProvider<...>.ServiceTypes.Indicators
property WorldBankDataProvider<...>.ServiceTypes.Country.Indicators: WorldBankDataProvider<...>.ServiceTypes.Indicators


<summary>The indicators for the country</summary>
val l : RuntimeImplementation.WorldBank.Indicator
val seriesOpts : HighchartsSeriesOptions
type HighchartsSeriesOptions

Full name: FunScript.TypeScript.HighchartsSeriesOptions
property HighchartsSeriesOptions.name: string
property RuntimeImplementation.WorldBank.Country.Name: string
property HighchartsSeriesOptions.data: obj array
val t : int
val y : float
type obj = System.Object

Full name: Microsoft.FSharp.Core.obj
member System.Collections.Generic.IList.pushOverload2 : params items:'T array -> float
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore
Fork me on GitHub