How does string comparison work in OCAML?

Posted by Steve Rowe on Stack Overflow See other posts from Stack Overflow or by Steve Rowe
Published on 2010-06-16T16:20:04Z Indexed on 2010/06/16 16:22 UTC
Read the original article Hit count: 367

Filed under:
|

From what I can tell, = and != is supposed to work on strings in OCAML. I'm seeing strange results though which I would like to understand better.

When I compare two strings with = I get the results I expect:

# "steve" = "steve";;
- : bool = true
# "steve" = "rowe";;
- : bool = false

but when I try != I do not:

# "steve" != "rowe";;
- : bool = true
# "steve" != "steve";; (* unexpected - shouldn't this be false? *)
- : bool = true

Can anyone explain? Is there a better way to do this?

© Stack Overflow or respective owner

Related posts about string

Related posts about ocaml