FunScript: F# to JavaScript with type providers

分享 jiyinyiyong 发表于 2 年前最后回复来自 qq2850071112 2 年前

又是微软家的编程语言呢, 用函数式编程语言来开发应用, Haskell 方向有 Elm 和 PureScript, 不知道微软这个能不能行, 可以关注下..

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.

// 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 
}
暂无回复,说出你的观点吧
登录后即可参与回复