F#类型不匹配

时间:2014-05-14 11:31:10

标签: f#

我正在将程序从Haskell转换为F#。无法访问.Net中的Haskell库。

这个声明有什么问题?

type Product = string


type Shopping = Product list

let p_tea = "Tea"
let p_sugar = "Sugar"
let p_coffee = "Coffee"
let p_biscuit = "Biscuit"
let p_milk = "Milk"
let p_soya = "Soya"

let shopping = [p_tea,p_sugar,p_coffee,p_biscuit,p_milk]

我收到以下错误。类似的声明在Haskell中有效.. !!

Type mismatch. Expecting a
    Shopping    
but given a
    (string * string * string * string * string) list    

2 个答案:

答案 0 :(得分:1)

F#使用逗号分隔元组中的元素,使用分号分隔集合中的元素。你想要:

let shopping = [p_tea; p_sugar; p_coffee; p_biscuit; p_milk]

答案 1 :(得分:0)

在F#list(和数组)中,项目用分号分隔。元组以逗号分隔。

type Product = string

type Shopping = Product list

let p_tea = "Tea"
let p_sugar = "Sugar"
let p_coffee = "Coffee"
let p_biscuit = "Biscuit"
let p_milk = "Milk"
let p_soya = "Soya"

let shopping = [p_tea; p_sugar; p_coffee; p_biscuit; p_milk]