【问题标题】:Xamarin Studio 6.0 F# Array.tail produces compilation errorXamarin Studio 6.0 F# Array.tai​​l 产生编译错误
【发布时间】:2016-04-15 01:21:05
【问题描述】:

我一直在 Win8.1 上使用 VS2015 在 F# 中开发,但我最近购买了 iMAC 并为 MacOS X elCapitan 10.11.3 安装了 Xamarin Studio 6.0

有一些代码可以在 VS2015 上正常编译,我正在尝试在 iMAC 上编译它。

Array.tai​​l 确实在 F# 交互中工作,但是 我对 Array.tai​​l 有一个编译错误

Projects/MyAlgos/MyAlgos/Program.fs(25,25):错误 FS0039:未定义值、构造函数、命名空间或类型“tail” (FS0039) (MyAlgos)

在 Xamarin 的解决方案资源管理器面板中,我将 Target Framework 设置为 .NET Framework 4.5.2,(就像在 VS2015 中设置的一样)

//////// Travelling Salesman problem ////////


open System
open System.Collections
open System.Collections.Generic
open System.IO

open System.Windows

open FSharp.Charting

//open MyLibrary
//open MyLibrary.MyUsefulFunctions
//open MyLibrary.MyCollections

exception InnerError of string


let stopWatch = System.Diagnostics.Stopwatch.StartNew()

///////////////// preparing the data /////////////////

// format of the files
//[number_of_cities]
//[x_1] [y_1] // coordinate

let x = File.ReadAllLines "C:\Users\Fagui\Documents\GitHub\Learning Fsharp\Algos\Algos\Stanford Algo II\Algo II - PA5 - TSP.txt"

let split (text:string)=
    text.Split [|'\t';' '|]

let splitInto2Values (A: string []) =  
    (float A.[0],float A.[1])

let parseLine (line:string) = 
    line
    |> split 
    |> splitInto2Values



let num_cities = int x.[0]

let cities = x |> Array.tail |> Array.map parseLine //  [x_1][y_1]

我也有这个相关的警告

/Library/Frameworks/Mono.framework/Versions/4.4.0/lib/mono/4.5/Microsoft.Common.targets:警告:此工具集不支持 TargetFrameworkVersion“v4.5.2”(ToolsVersion:4.0)。 (我的算法)

【问题讨论】:

    标签: arrays xamarin compiler-errors f#


    【解决方案1】:

    让城市= x |> Array.tai​​l |> Array.map parseLine

    错误 FS0039:未定义值、构造函数、命名空间或类型“tail” (FS0039) (MyAlgos)

    我没有在编译代码(或交互式)中找不到 Array.tail 的任何问题。

    您是否尝试过创建 F# 控制台项目并仅进行简单的 Array.tail 测试?请参阅下面的示例源代码。

    来源:

    [<EntryPoint>]
    let main argv = 
        let array3 = [| 1; 2; 3 |]
        let array2 = array3 |> Array.tail
        let array1 = array2 |> Array.tail
        printfn "%A\n%A\n%A" array3 array2 array1
    
        0 // return an integer exit code
    

    输出:

    [|1; 2; 3|]
    [|2; 3|]
    [|3|]
    
    Press any key to continue...
    

    我的版本信息:

    >fsharpc
    F# Compiler for F# 4.0 (Open Source Edition)
    Freely distributed under the Apache 2.0 Open Source License
    >mono --version
    Mono JIT compiler version 4.2.3
    

    删除框架警告:

    要删除框架警告,您可以将项目设置为“Mono / Net 4.5”

    【讨论】:

    • 很高兴听到...快乐 F#'ing;-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-15
    • 1970-01-01
    相关资源
    最近更新 更多