Reputation: 25
I am converting a program from Haskell to F#. Having trouble accessing the Haskell Library in .Net.
What is wrong with this declaration?
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]
I get the following error.. Similar declaration works in Haskell.. !!
Type mismatch. Expecting a
Shopping
but given a
(string * string * string * string * string) list
Upvotes: 0
Views: 219
Reputation: 14468
F# uses commas to separate elements in a tuple, and semicolons to separate elements in a collection. You want:
let shopping = [p_tea; p_sugar; p_coffee; p_biscuit; p_milk]
Upvotes: 1
Reputation: 7560
In F# list (and array) items are separated by a semicolon. Tuples are separated by commas.
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]
Upvotes: 0