0

I have some SML code trying to match for specific strings for a project but I can't get this case statement to work (previously had if statements but after 3 it was going to be too messy).

case op_name of 
  "pair" => print "some pair"
| "equal" | "member" | "union" => print "some operation"
| _ => print "failed"

Currently I'm getting an error Error: syntax error: replacing BAR with DARROW on the second-last line after the | but I can't find any reference of this sort of Case in SML so I was just trying something I imagined could work. I'm trying to essentially get the equivalent of C code

switch(input) {
  case 5: 
    printf("some pair"); 
    break;
  case 6:
  case 7: 
  case 8:
    printf("some operation");
    break;
  default: printf("failed");
Grzegorz
  • 107
  • 8
  • I've marked this question as a duplicate, but let me know if the linked answer does not satisfy you. – Ionuț G. Stan Mar 17 '17 at 11:58
  • BTW, your attempt would work with SML/NJ if you wrap the three cases inside parantheses: `| ("equal" | "member" | "union") =>`. – Ionuț G. Stan Mar 17 '17 at 12:00
  • Thank you very much, that answer was what I needed. I searched a bunch but I couldn't find that question either when I wrote it or when I was Googling and yeah your suggestion did work, thank you :) – Grzegorz Mar 17 '17 at 12:06

0 Answers0