Reputation: 1127
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
Upvotes: 0
Views: 17667
Reputation: 41290
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
Upvotes: 10