FunScript 是一个轻量级的 F# 库,可以让你快速开发单页 Web 应用。你可以连接到外部数据源并调用 REST API,生成面板,使用 JavaScript 可视化库,编写异步计算。
示例代码:
// 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 }