How to write a case list pattern matching in OCaml?

Viewed 125

I want to do something like the following Go code:

 switch c {
    case ' ', '\t', '\n', '\f', '\r':
        return true
 }

But I can't find an example in the OCaml manual.

Is this possible in OCaml?

1 Answers

OCaml doesn't have switch statements. It has "pattern matching" which is something a bit more general than a switch statement.

You can read more about this here

Your Go code could be translated to this (from the top of my head):

match c with 
| ' ' | '\t' | '\n' | '\012' (* '\f' *) | '\r' -> true
| _ -> false
Related