Programming languages Coursera编程语言hw2
//val officiate=fn:卡片列表*移动列表*整数->整数 //val分数=fn:卡片列表*int->int 当我使用此函数时,我发现了以下错误:Programming languages Coursera编程语言hw2,programming-languages,sml,Programming Languages,Sml,//val officiate=fn:卡片列表*移动列表*整数->整数 //val分数=fn:卡片列表*int->int 当我使用此函数时,我发现了以下错误: 使用“hw2.sml”; [开启hw2.sml] hw2.sml:137.6-137.48错误:运算符不是函数[tycon不匹配] 接线员:int 在表达上: 分数(附录(clist,mlist,score,score) val it=():单位 我之前设置的数据类型: 我使用我以前创建的评分函数,它可以正常工作: datat
- 使用“hw2.sml”;
[开启hw2.sml]
hw2.sml:137.6-137.48错误:运算符不是函数[tycon不匹配]
接线员:int
在表达上:
分数(附录(clist,mlist,score,score)
val it=():单位
我使用我以前创建的评分函数,它可以正常工作:
datatype suit = Clubs | Diamonds | Hearts | Spades
datatype rank = Jack | Queen | King | Ace | Num of int
type card = suit * rank
datatype color = Red | Black (*spades and clubs are black,diamonds and hearts are red)*)
datatype move = Discard of card | Draw
exception IllegalMove
我知道了,我可以使用变量score,它是score函数。对不起,我不能使用变量score,它是score函数。重命名
score
参数。
datatype suit = Clubs | Diamonds | Hearts | Spades
datatype rank = Jack | Queen | King | Ace | Num of int
type card = suit * rank
datatype color = Red | Black (*spades and clubs are black,diamonds and hearts are red)*)
datatype move = Discard of card | Draw
exception IllegalMove
fun score (xs, score) =
let val sum = sum_cards(xs)
in
case (all_same_color(xs), sum > score) of
(true, true) => (3 * (sum - score)) div 2
| (true, false) => (score - sum) div 2
| (false, true) => 3 * (sum - score)
| (false, false) => score - sum
end