# "this match case is unused"

**URL:** https://discuss.ocaml.org/t/this-match-case-is-unused/3555
**Category:** Learning
**Created:** [March 23, 2019, 7:02pm UTC](https://discuss.ocaml.org/t/this-match-case-is-unused/3555 "2019-03-23T19:02:00Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![illio](https://avatars.discourse-cdn.com/v4/letter/i/d26b3c/32.png) [@illio](https://discuss.ocaml.org/u/illio)
#### Post date: [March 23, 2019, 7:02pm UTC](https://discuss.ocaml.org/t/this-match-case-is-unused/3555/1 "2019-03-23T19:02:00Z")

</div>

Hello, I just started coding in ocaml and I am blocked on an exercise where I am supposed to create a function that count the number of times an x number appear on an odd rank in a list ( I don’t know if it’s understandable english is not my first language 😕 ) . So that’s what I came up with but the terminal sends ma a warning:  
Warning 11: this match case is unused.  
val nbf1 : 'a list -\> 'a -\> int = "

I think I’m supposed to ad an “in …” a the end of it but i’m not sure… f someone could help me figure it out.

Thanks in advance 🙂

 ![Capture%20du%202019-03-23%2019-54-54](https://us1.discourse-cdn.com/flex020/uploads/ocaml/original/2X/e/ee973750e3e2506fc09197b9fb4009bf57b56aa8.png)

---

<div class="post-metadata">

### Author: ![RogerT](https://avatars.discourse-cdn.com/v4/letter/r/5f8ce5/32.png) [@RogerT](https://discuss.ocaml.org/u/RogerT)
#### Post date: [March 23, 2019, 7:50pm UTC](https://discuss.ocaml.org/t/this-match-case-is-unused/3555/2 "2019-03-23T19:50:42Z")

</div>

Hi  
You mean that `nbf1 [1 ; 2 ; 9 ; 5 ; 7 ; 9] 9` should give 1.  
And `nbf1 [9 ; 2 ; 9 ; 5 ; 9 ; 8] 9` should give 3.

With your code I see warning 8 (not exhaustive PM) and warning 11 (unused match case):

```auto
let nbf1 l x =
let rec nbf l x acc =
match l with 
  | [] -> acc
  | a::b::t -> if a = x then nbf t x (acc + 1) else nbf t x acc
  | a::b::[] -> if a = x then acc + 1 else acc in 
nbf l x 0

```

> Characters 37-169:  
> match l with  
> | → acc  
> | a :: b :: t → if a = x then nbf t x (acc + 1) else nbf t x acc  
> | a :: b :: → if a = x then acc + 1 else acc  
> Warning 8: this pattern-matching is not exhaustive.  
> Here is an example of a value that is not matched:  
> \_ ::   
> Characters 127-135:  
> | a :: b :: → if a = x then acc + 1 else acc  
> ^^^^^^^^  
> Warning 11: this match case is unused.

Case 3 is case 2 with t = , so it’s not a correct pattern-matching.

You should organize your match cases as follows:  
empty list  
list with one element  
list with at least 2 elements with possibly empty tail:

```auto
let nbf1 l x =
let rec nbf l x acc =
match l with 
  | [] -> acc
  | a::[] -> if a = x then acc + 1 else acc
  | a::b::t -> if a = x then nbf t x (acc + 1) else nbf t x acc in 
nbf l x 0

val nbf1 : 'a list -> 'a -> int = <fun>

```

```auto
# nbf1 [9 ; 2 ; 9 ; 5 ; 9 ; 8] 9
- : int = 3

```

---

<div class="post-metadata">

### Author: ![illio](https://avatars.discourse-cdn.com/v4/letter/i/d26b3c/32.png) [@illio](https://discuss.ocaml.org/u/illio)
#### Post date: [March 23, 2019, 7:51pm UTC](https://discuss.ocaml.org/t/this-match-case-is-unused/3555/3 "2019-03-23T19:51:49Z")

</div>

I managed to get rid of the warning by adding a condition but it still doesn’t give me any results when I try the function with a certain list

 ![Capture%20du%202019-03-23%2020-51-20](https://us1.discourse-cdn.com/flex020/uploads/ocaml/original/2X/4/4d27c7d4c9ea55fb5190ebfbb36438158e7e8507.png)

---

<div class="post-metadata">

### Author: ![RogerT](https://avatars.discourse-cdn.com/v4/letter/r/5f8ce5/32.png) [@RogerT](https://discuss.ocaml.org/u/RogerT)
#### Post date: [March 23, 2019, 7:52pm UTC](https://discuss.ocaml.org/t/this-match-case-is-unused/3555/4 "2019-03-23T19:52:02Z")

</div>

PS  
You should use \</\> tool in the editor to highlight your OCaml program.

I encourage you to write your code in a strutured (and in a somehow modular way), as shown above.

---

<div class="post-metadata">

### Author: ![illio](https://avatars.discourse-cdn.com/v4/letter/i/d26b3c/32.png) [@illio](https://discuss.ocaml.org/u/illio)
#### Post date: [March 23, 2019, 7:57pm UTC](https://discuss.ocaml.org/t/this-match-case-is-unused/3555/5 "2019-03-23T19:57:05Z")

</div>

I think I understood where my mistakes were thank you very much

---

<div class="post-metadata">

### Author: ![illio](https://avatars.discourse-cdn.com/v4/letter/i/d26b3c/32.png) [@illio](https://discuss.ocaml.org/u/illio)
#### Post date: [March 23, 2019, 7:58pm UTC](https://discuss.ocaml.org/t/this-match-case-is-unused/3555/6 "2019-03-23T19:58:02Z")

</div>

I agree with I just find it hard to organize it on the terminal since I can’t use the tab button

---

<div class="post-metadata">

### Author: ![RogerT](https://avatars.discourse-cdn.com/v4/letter/r/5f8ce5/32.png) [@RogerT](https://discuss.ocaml.org/u/RogerT)
#### Post date: [March 23, 2019, 8:00pm UTC](https://discuss.ocaml.org/t/this-match-case-is-unused/3555/7 "2019-03-23T20:00:56Z")

</div>

At least use ledit  
`$ ledit ocaml`  
You can create an alias in your ~/.bashrc (or equivalent config file).

Or Utop.

For a serious work, it’s much better to use Emacs or Vim.

ocaml-top is certainly a good option to write clean and structured OCaml programs (but with no text edition features).

---

<div class="post-metadata">

### Author: ![illio](https://avatars.discourse-cdn.com/v4/letter/i/d26b3c/32.png) [@illio](https://discuss.ocaml.org/u/illio)
#### Post date: [March 23, 2019, 8:03pm UTC](https://discuss.ocaml.org/t/this-match-case-is-unused/3555/8 "2019-03-23T20:03:48Z")

</div>

I am using ledit ocaml already but I’ll start using Emacs.

---

<div class="post-metadata">

### Author: ![cloudyhug](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/cloudyhug/32/2399_2.png) [@cloudyhug](https://discuss.ocaml.org/u/cloudyhug)
#### Post date: [March 24, 2019, 10:49am UTC](https://discuss.ocaml.org/t/this-match-case-is-unused/3555/9 "2019-03-24T10:49:56Z")

</div>

You can also use **Visual Studio Code** with the **OCaml/Reason** plugin. You will be able to benefit from autocomplete, and your programs will be typechecked on the fly with a tool called **merlin** , as long as you are writing files in a `src` directory. It basically means you will not have to recompile everything manually every time you add something to your program. The plugin also reads the other files in the directory, in case you are using elements that are defined in those other files. As a build tool, I suggest you use `ocamlbuild` or `dune`, which are powerful and pretty automatic.

---

<div class="post-metadata">

### Author: ![illio](https://avatars.discourse-cdn.com/v4/letter/i/d26b3c/32.png) [@illio](https://discuss.ocaml.org/u/illio)
#### Post date: [March 24, 2019, 12:49pm UTC](https://discuss.ocaml.org/t/this-match-case-is-unused/3555/10 "2019-03-24T12:49:55Z")

</div>

Thank you I’ll check these out too 😄

---

<div class="post-metadata">

### Author: ![RogerT](https://avatars.discourse-cdn.com/v4/letter/r/5f8ce5/32.png) [@RogerT](https://discuss.ocaml.org/u/RogerT)
#### Post date: [March 24, 2019, 7:28pm UTC](https://discuss.ocaml.org/t/this-match-case-is-unused/3555/11 "2019-03-24T19:28:33Z")

</div>

> [@cloudyhug](#):
>
> You can also use **Visual Studio Code**

As discussed in another topic a few months ago, VSC is enough (and nice) for editing code. But I didn’t find what is a key feature for programming and even a must have feature for learning: the REPL.  
Has it recently changed?  
How do you evaluate a selection/region/file?

---

<div class="post-metadata">

### Author: ![cloudyhug](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/cloudyhug/32/2399_2.png) [@cloudyhug](https://discuss.ocaml.org/u/cloudyhug)
#### Post date: [March 24, 2019, 8:43pm UTC](https://discuss.ocaml.org/t/this-match-case-is-unused/3555/12 "2019-03-24T20:43:39Z")

</div>

This is the main point of people not using that kind of text editors. While I understand what you mean, I have personally not actively looked for a REPL feature in VSCode since I started using it. I still do not know whether that kind of tools exists. I actually started learning OCaml with only VSCode and a terminal in another window. I was launching `rlwrap ocaml` and loading the file with `#use "file.ml"`. When I needed to evaluate the file again, I would just switch windows, press the up arrow and Enter. In more advanced projects, I even feel like autocomplete and static analysis are sufficient in order to be productive, as the tests are often macro tests of all the modules working together as a whole, on some input files for example. I do not want to generalise my case too much, but for my projects, as the language has really clear syntax and semantics, most of the errors are avoided with type checking.

---

<div class="post-metadata">

### Author: ![steinuil](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/steinuil/32/993_2.png) [@steinuil](https://discuss.ocaml.org/u/steinuil)
#### Post date: [March 25, 2019, 8:19am UTC](https://discuss.ocaml.org/t/this-match-case-is-unused/3555/13 "2019-03-25T08:19:46Z")

</div>

> [@RogerT](#):
>
> How do you evaluate a selection/region/file?

I don’t think you can with merlin. If you use [dune](https://dune.build/) you can do `dune utop` at a terminal and you will get a REPL in which you can access all the modules in your project.

---

<div class="post-metadata">

### Author: ![n4323](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@n4323](https://discuss.ocaml.org/u/n4323)
#### Post date: [March 25, 2019, 1:33pm UTC](https://discuss.ocaml.org/t/this-match-case-is-unused/3555/14 "2019-03-25T13:33:52Z")

</div>

For what it’s worth, after some iterations I now use a setup where I have one editor window open (vim in my case) and a terminal window which runs tmux, and in the tmux session, utop is running. I have set up my editor to send highlighted text regions to tmux with a shortcut command – this is possible in vim via a plugin, and I’m sure other editors can do it too. This setup replicates the evaluate-region feature many IDEs have.
