title: Custom datatypes in SML
body: <p>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</p>
  
  <pre><code>datatype suit = Spades | Clubs | Hearts | Diamonds;
  </code></pre>
  
  <p>Now I want to write a function that takes a suit and returns a string representation of it. Here it is currently</p>
  
  <pre><code>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";
  </code></pre>
  
  <p>It compiles fine but when I try to call it with each suit</p>
  
  <pre><code>suitname Hearts;
  suitname Spades;
  suitname Clubs;
  suitname Diamonds;
  </code></pre>
  
  <p>I get this error</p>
  
  <p><a href="https://i.stack.imgur.com/q1D7p.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q1D7p.jpg" alt="enter image description here"></a></p>
  
  <p>and have no idea why. Any help would be appreciated greatly!</p>