【发布时间】:2019-05-19 16:18:42
【问题描述】:
我正在尝试创建一个接受卡片列表并返回其中没有特定卡片的列表的函数。如何将已定义类型的列表传递给函数?
我向函数传递了一个列表,它指出我的类型不匹配。
type Suit = Clubs | Diamonds | Hearts | Spades
type Rank = Jack | Queen | King | Ace | Num of int
type Card = Rank * Suit
type Color = Red | Black
type Move = Discard of Card | Draw
let cards = [(Jack,Clubs); (Num(8),Spades)]
let c:Card = Jack, Clubs
let remove_card (cs, c:Card, e:string) =
cs
remove_card cards c "Err"
调用函数 remove_card 时期望列表正确返回。 但是,抛出错误:
这个表达式应该有类型 '('a -> 'b -> 'c) * 卡片 * 字符串' 但这里有类型 '(等级 * 花色)列表'
【问题讨论】: