輕量級的 F# 庫:FunScript

jopen 10年前發布 | 14K 次閱讀 FunScript

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 
}

項目主頁:http://www.baiduhome.net/lib/view/home/1418001917808

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!