Ocaml This '(' might be unmatched
up vote
1
down vote
favorite
new to Ocaml. I've no clue what is happening here and I've been trying to solve this for maybe 2 hours.
Here is the code:
let hailstorm n =
match n with
| (mod n 2 == 0) -> (n/2)
| (mod n 2 == 1) -> (3*n+1);;
When I try to compile it says:
File "./x.ml", line 3, characters 11-12:Error: Syntax error: ')' expected
File "./x.ml", line 3, characters 6-7:
Error: This '(' might be unmatched
ocaml
add a comment |
up vote
1
down vote
favorite
new to Ocaml. I've no clue what is happening here and I've been trying to solve this for maybe 2 hours.
Here is the code:
let hailstorm n =
match n with
| (mod n 2 == 0) -> (n/2)
| (mod n 2 == 1) -> (3*n+1);;
When I try to compile it says:
File "./x.ml", line 3, characters 11-12:Error: Syntax error: ')' expected
File "./x.ml", line 3, characters 6-7:
Error: This '(' might be unmatched
ocaml
3
Did you mean tomatch mod n 2 with | 0 -> …; 1 -> …;
?
– Bergi
Nov 9 at 11:23
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
new to Ocaml. I've no clue what is happening here and I've been trying to solve this for maybe 2 hours.
Here is the code:
let hailstorm n =
match n with
| (mod n 2 == 0) -> (n/2)
| (mod n 2 == 1) -> (3*n+1);;
When I try to compile it says:
File "./x.ml", line 3, characters 11-12:Error: Syntax error: ')' expected
File "./x.ml", line 3, characters 6-7:
Error: This '(' might be unmatched
ocaml
new to Ocaml. I've no clue what is happening here and I've been trying to solve this for maybe 2 hours.
Here is the code:
let hailstorm n =
match n with
| (mod n 2 == 0) -> (n/2)
| (mod n 2 == 1) -> (3*n+1);;
When I try to compile it says:
File "./x.ml", line 3, characters 11-12:Error: Syntax error: ')' expected
File "./x.ml", line 3, characters 6-7:
Error: This '(' might be unmatched
ocaml
ocaml
asked Nov 9 at 11:13
bg9848
455
455
3
Did you mean tomatch mod n 2 with | 0 -> …; 1 -> …;
?
– Bergi
Nov 9 at 11:23
add a comment |
3
Did you mean tomatch mod n 2 with | 0 -> …; 1 -> …;
?
– Bergi
Nov 9 at 11:23
3
3
Did you mean to
match mod n 2 with | 0 -> …; 1 -> …;
?– Bergi
Nov 9 at 11:23
Did you mean to
match mod n 2 with | 0 -> …; 1 -> …;
?– Bergi
Nov 9 at 11:23
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
The keyword mod
is a binary operator (like lsl
, lsr
, asr
, land
, lor
, lxor
and or
) . For instance,
let zero = 2 mod 2
Binary operator can be transformed into standard function by wrapping them around parentheses,
let zero = (mod) 2 2
this is why the parser is expecting a closing parenthesis after (mod
.
Then, you pattern matching is wrong because n mod 2 == 0
is an expression, not a pattern (and you should use structural equality =
rather than physical equality ==
):
let f n = match n mod 2 with
| 0 -> ...
| _ -> ...
or
let f n = match n mod 2 = 0 with
| true -> ...
| false -> ...
which is probably simpler with an if ... then ... else ...
.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
The keyword mod
is a binary operator (like lsl
, lsr
, asr
, land
, lor
, lxor
and or
) . For instance,
let zero = 2 mod 2
Binary operator can be transformed into standard function by wrapping them around parentheses,
let zero = (mod) 2 2
this is why the parser is expecting a closing parenthesis after (mod
.
Then, you pattern matching is wrong because n mod 2 == 0
is an expression, not a pattern (and you should use structural equality =
rather than physical equality ==
):
let f n = match n mod 2 with
| 0 -> ...
| _ -> ...
or
let f n = match n mod 2 = 0 with
| true -> ...
| false -> ...
which is probably simpler with an if ... then ... else ...
.
add a comment |
up vote
2
down vote
The keyword mod
is a binary operator (like lsl
, lsr
, asr
, land
, lor
, lxor
and or
) . For instance,
let zero = 2 mod 2
Binary operator can be transformed into standard function by wrapping them around parentheses,
let zero = (mod) 2 2
this is why the parser is expecting a closing parenthesis after (mod
.
Then, you pattern matching is wrong because n mod 2 == 0
is an expression, not a pattern (and you should use structural equality =
rather than physical equality ==
):
let f n = match n mod 2 with
| 0 -> ...
| _ -> ...
or
let f n = match n mod 2 = 0 with
| true -> ...
| false -> ...
which is probably simpler with an if ... then ... else ...
.
add a comment |
up vote
2
down vote
up vote
2
down vote
The keyword mod
is a binary operator (like lsl
, lsr
, asr
, land
, lor
, lxor
and or
) . For instance,
let zero = 2 mod 2
Binary operator can be transformed into standard function by wrapping them around parentheses,
let zero = (mod) 2 2
this is why the parser is expecting a closing parenthesis after (mod
.
Then, you pattern matching is wrong because n mod 2 == 0
is an expression, not a pattern (and you should use structural equality =
rather than physical equality ==
):
let f n = match n mod 2 with
| 0 -> ...
| _ -> ...
or
let f n = match n mod 2 = 0 with
| true -> ...
| false -> ...
which is probably simpler with an if ... then ... else ...
.
The keyword mod
is a binary operator (like lsl
, lsr
, asr
, land
, lor
, lxor
and or
) . For instance,
let zero = 2 mod 2
Binary operator can be transformed into standard function by wrapping them around parentheses,
let zero = (mod) 2 2
this is why the parser is expecting a closing parenthesis after (mod
.
Then, you pattern matching is wrong because n mod 2 == 0
is an expression, not a pattern (and you should use structural equality =
rather than physical equality ==
):
let f n = match n mod 2 with
| 0 -> ...
| _ -> ...
or
let f n = match n mod 2 = 0 with
| true -> ...
| false -> ...
which is probably simpler with an if ... then ... else ...
.
answered Nov 9 at 15:58
octachron
4,0881413
4,0881413
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224659%2focaml-this-might-be-unmatched%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Did you mean to
match mod n 2 with | 0 -> …; 1 -> …;
?– Bergi
Nov 9 at 11:23