首页 > 代码库 > Windows PowerShell 会话中使用 FSharp 代码编译器

Windows PowerShell 会话中使用 FSharp 代码编译器

Windows PowerShell 会话中使用 FSharp 代码编译器

 

<#

$fSharpCode= @"

moduleTest

  let HelloWorld =

    "Hello World!!!!"

  printfn "%s" HelloWorld

 

  let rec Loop n =

    seq [

      if n <= 0 then

          ()

      else

          yield n;

          yield! Loop (n-1)

    ] |> Seq.sort

  printfn "%A" (Loop 5)

 

  let rec factorial x =

  if x = 0 then 1

  else x * (factorial (x - 1))

 

"@

#>

 

$env:Path=$env:Path+";C:\ProgramFiles\Microsoft SDKs\F#\3.0\Framework\v4.0"

Add-Type-PathC:\FSharpPowerPack-4.0.0.0\bin\FSharp.Compiler.CodeDom.dll

$provider=New-ObjectMicrosoft.FSharp.Compiler.CodeDom.FSharpCodeProvider

 

$fSharpCode=Get-Content"C:\Users\tj\Desktop\loop.fs"|Out-String

 

$fsharpType=Add-Type-TypeDefinition$fSharpCode-CodeDomProvider$provider-PassThru|where { $_.IsPublic }

 

$fSharpType::HelloWorld

$fSharpType::Loop(9)

$fsharpType::factorial(9)

 

############

 

$env:Path=$env:Path+";C:\ProgramFiles\Microsoft SDKs\F#\3.0\Framework\v4.0"

Add-Type-PathC:\FSharpPowerPack-4.0.0.0\bin\FSharp.Compiler.CodeDom.dll

$provider=New-ObjectMicrosoft.FSharp.Compiler.CodeDom.FSharpCodeProvider

 

$fSharpCode2=Get-Content"C:\Users\tj\Desktop\Line.fs"|Out-String

 

$fsharpType=Add-Type-TypeDefinition$fSharpCode2-CodeDomProvider$provider-ReferencedAssemblies @("System.Drawing";"C:\fsharp-FSharp.Charting\bin\FSharp.Charting.dll")-PassThru|where { $_.IsPublic }

Add-Type-Path"C:\fsharp-FSharp.Charting\bin\FSharp.Charting.dll"

 

$fsharpType::Line

 

######################

 

$env:Path=$env:Path+";C:\ProgramFiles\Microsoft SDKs\F#\3.0\Framework\v4.0"

Add-Type-PathC:\FSharpPowerPack-4.0.0.0\bin\FSharp.Compiler.CodeDom.dll

$provider=New-ObjectMicrosoft.FSharp.Compiler.CodeDom.FSharpCodeProvider

 

$fSharpCode3=Get-Content"C:\Users\tj\Desktop\Data.fs"|Out-String

 

$fsharpType=Add-Type-TypeDefinition$fSharpCode3-CodeDomProvider$provider-ReferencedAssemblies @("C:\FSharp.Data\bin\FSharp.Data.dll")-PassThru| where { $_.IsPublic }

Add-Type-PathC:\FSharp.Data\bin\FSharp.Data.dll

 

$fsharpType::http("http://www.baidu.com")

$fsharpType::http("http://www.federalreserve.gov/datadownload/Output.aspx?rel=H15&series=bcb44e57fb57efbe90002369321bfb3f&lastObs=&from=&to=&filetype=csv&label=include&layout=seriescolumn")