I'm playing around with datatypes in SML for the first time. I've defined a datatype called suit with the four suits of playing cards
datatype suit = Spades | Clubs | Hearts | Diamonds;
Now I want to write a function that takes a suit and returns a string representation of it. Here it is currently
fun suitname(x) =
if x = Spades then
"Spades"
else if x = Clubs then
"Clubs"
else if x = Diamonds then
"Diamonds"
else if x = Hearts then
"Hearts"
else
"Undefined suit";
It compiles fine but when I try to call it with each suit
suitname Hearts;
suitname Spades;
suitname Clubs;
suitname Diamonds;
I get this error
and have no idea why. Any help would be appreciated greatly!
case x of Spades => "Spades" | Clubs => "Clubs" | Diamonds => "Diamonds" | Hearts => "Hearts"
– Colonel Thirty Two