0

I have the follwing function that is suppose to return the value of a card. I'm not sure why the case Num => Num is giving the following error:

Error: Types of rules don't agree, Earlier rules rank->int this rule rank->int->rank

Why would Num=>Num have the return type rank->int->rank

 datatype suit = Clubs | Diamonds | Hearts | Spades
 datatype rank = Jack | Queen | King | Ace | Num of int 
 type card = suit * rank


 fun card_value (suit, rank)=
 case rank of
    Ace =>11
     | Jack =>10
     | King =>10
     | Queen =>10
     | Num => Num ;


card_value(Clubs,Ace); //calling function
2
  • 9
    Coursera homework? ;-) Commented Jan 30, 2013 at 12:33
  • It absolutely is coursera homework. It sucks that peaople ask for answers and not do it on their own. Commented Mar 23, 2022 at 14:33

1 Answer 1

10

The error message is indicative. You need to have the same return type for all patterns.

fun card_value (suit, rank) =
  case rank of
      Ace => 14
    | King => 13
    | Queen => 12
    | Jack => 11
    | Num i => i

So you have to specify the correct constructor Num i (not Num only) and return i as an int

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.