Coursera编程语言hw2

问题描述 投票:-1回答:1
fun officiate (clist , mlist , score) =
    let val hlist = []
    in
      let
        fun appendh ([], _, score) = hlist
          | appendh (_, [], score) = hlist 
          | appendh (c :: clist', m :: mlist', score) = 
        case (sum_cards(hlist) > score, m) of
            (true, _) => hlist
          | (false, Draw) => c :: appendh(clist', mlist', score)
          | (false, Discard a) => remove_card(hlist, a, IllegalMove) @ appendh(clist', mlist', score)                            
      in
        score(appendh(clist, mlist, score), score)
      end
    end

// val officiate = fn:卡列表*移动列表* int-> int

// val分数= fn:卡片列表* int-> int

当我使用此功能时,发现了这个错误:


  • 使用“ hw2.sml”;[打开hw2.sml]hw2.sml:137.6-137.48错误:运算符不是函数[tycon不匹配]运算子:int表达:得分(附录(clist,mlist,得分),得分)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

并且我使用之前创建的得分函数,它可以正常工作:

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
programming-languages sml
1个回答
0
投票

我知道了,我可以使用变量score这是得分函数。

© www.soinside.com 2019 - 2024. All rights reserved.