Matching of tuples

Posted by Jack on Stack Overflow See other posts from Stack Overflow or by Jack
Published on 2010-06-13T17:28:10Z Indexed on 2010/06/13 17:32 UTC
Read the original article Hit count: 285

Filed under:
|
|

From what I understood I can use pattern-matching in a match ... with expression with tuples of values, so something like

match b with
  ("<", val) -> if v < val then true else false
  | ("<=", val) -> if v <= val then true else false

should be correct but it gives me a syntax error as if the parenthesis couldn't be used:

File "ocaml.ml", line 41, characters 14-17: Error: Syntax error: ')' expected

File "ocaml.ml", line 41, characters 8-9: Error: This '(' might be unmatched

referring on first match clause..

Apart from that, can I avoid matching strings and applying comparisons using a sort of eval of the string? Or using directly the comparison operator as the first element of the tuple?

© Stack Overflow or respective owner

Related posts about pattern-matching

Related posts about ocaml