# Unexpected partial-match warning on a malformed program

**URL:** <https://discuss.ocaml.org/t/unexpected-partial-match-warning-on-a-malformed-program/14255>\
**Category:** Learning\
**Created:** [March 6, 2024, 4:25am UTC](https://discuss.ocaml.org/t/unexpected-partial-match-warning-on-a-malformed-program/14255 "2024-03-06T04:25:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zeta](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/zeta/32/6003_2.png) [@Zeta](https://discuss.ocaml.org/u/Zeta)\
**Post date:** [March 6, 2024, 4:25am UTC](https://discuss.ocaml.org/t/unexpected-partial-match-warning-on-a-malformed-program/14255/1 "2024-03-06T04:25:22Z")

</div>

OCaml gives me a `pattern-match` warning on expressions I think are malformed, e.g., `let x + 1 = 2`:

```ocaml
─( 13:26:24 )─< command 0 >────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # let x + 1 = 2;;

Line 1, characters 6-13:
Warning 8 [partial-match]: this pattern-matching is not exhaustive.
Here is an example of a case that is not matched:
0

val x : int -> int = <fun>
─( 13:26:25 )─< command 1 >────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # x 1;;
- : int = 2
─( 13:26:28 )─< command 2 >────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # x 2;;
Exception: Match_failure ("//toplevel//", 1, 6).
─( 13:26:30 )─< command 3 >────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # let x - 1 = 0;;

Line 1, characters 6-13:
Warning 8 [partial-match]: this pattern-matching is not exhaustive.
Here is an example of a case that is not matched:
0

val x : int -> int = <fun>
─( 13:26:32 )─< command 4 >────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # x (-1);;
- : int = 0
─( 13:26:36 )─< command 5 >────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # x 0;;
Exception: Match_failure ("//toplevel//", 1, 6).

```

Expressions like `let x * 2 = 0` are rejected due to syntax error.  
Is this a bug?

---

<div class="post-metadata">

**Author:** ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)\
**Post date:** [March 6, 2024, 6:18am UTC](https://discuss.ocaml.org/t/unexpected-partial-match-warning-on-a-malformed-program/14255/2 "2024-03-06T06:18:10Z")

</div>

> [@Zeta](#):
>
> Is this a bug?

I don’t think so: the term `+ 1` is a valid pattern in OCaml (pattern matching on ints), so `let x + 1 = 2` is parsed as a functional binding `let x p = e` where `p` is the (non-exhaustive) pattern `+ 1` and `e` is `2`.

Cheers,  
Nicolas

---

<div class="post-metadata">

**Author:** ![emillon](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/emillon/32/1206_2.png) [@emillon](https://discuss.ocaml.org/u/emillon)\
**Post date:** [March 6, 2024, 10:12am UTC](https://discuss.ocaml.org/t/unexpected-partial-match-warning-on-a-malformed-program/14255/3 "2024-03-06T10:12:30Z")

</div>

> [@Zeta](#):
>
> `let x + 1 = 2`

To add to the explanation, I’d add that this is parsed as `let x (+1) = 2` which is like `let x 1 = 2`.

---

<div class="post-metadata">

**Author:** ![Zeta](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/zeta/32/6003_2.png) [@Zeta](https://discuss.ocaml.org/u/Zeta)\
**Post date:** [March 6, 2024, 10:28am UTC](https://discuss.ocaml.org/t/unexpected-partial-match-warning-on-a-malformed-program/14255/4 "2024-03-06T10:28:57Z")

</div>

Thanks for clarifying!
