F#类型不匹配
我正在将一个程序从Haskell转换为F#。无法访问.Net中的Haskell库 这个声明有什么问题F#类型不匹配,f#,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 =
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
在F#列表(和数组)中,项目用分号分隔。元组由逗号分隔
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]
F#使用逗号分隔元组中的元素,使用分号分隔集合中的元素。你想要:
let shopping = [p_tea; p_sugar; p_coffee; p_biscuit; p_milk]
这看起来像一个元组列表。可能你想用;作为分隔符。旁注,更惯用的F应该是
type Product=|字符串的乘积
。类型别名相对不常见。