# What this code mean in ocaml

**URL:** <https://discuss.ocaml.org/t/what-this-code-mean-in-ocaml/980>\
**Category:** Learning\
**Created:** [October 18, 2017, 2:26pm UTC](https://discuss.ocaml.org/t/what-this-code-mean-in-ocaml/980 "2017-10-18T14:26:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ranamustafa](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@ranamustafa](https://discuss.ocaml.org/u/ranamustafa)\
**Post date:** [October 18, 2017, 2:26pm UTC](https://discuss.ocaml.org/t/what-this-code-mean-in-ocaml/980/1 "2017-10-18T14:26:57Z")

</div>

Hi,  
i have this function avec (exn -\> bool) that convert exception of type exn to bool . the problem is that i dont understand how its works and use change it.  
function Not\_found -\> true | \_ -\> false

thank you

---

<div class="post-metadata">

**Author:** ![MiloDavis](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/milodavis/32/475_2.png) [@MiloDavis](https://discuss.ocaml.org/u/MiloDavis)\
**Post date:** [October 18, 2017, 2:53pm UTC](https://discuss.ocaml.org/t/what-this-code-mean-in-ocaml/980/2 "2017-10-18T14:53:52Z")

</div>

The `function` keyword in OCaml is syntactic sugar for `(fun x -> match x with ...)`, essentially it simplifies defining some functions by immediately matching on the input.

Your example could also be written

```auto
(fun x -> 
  match x with
   | Not_found -> true
   | _ -> false)

```

This function can be called just like any other OCaml function. Here are two short examples:

```auto
(function Not_found -> true | _ -> false) Not_found;; (* evaluates to true *)
(function Not_found -> true | _ -> false) (Invalid_argument "Invalid arg exn");; (* evaluates to false *)

```

You can also bind this function to a variable and use it that way.

```auto
let is_not_found = function 
  | Not_found -> true
  | _ -> false;;

```

This function can now be used in the rest of your program.

```auto
is_not_found Not_found;; (* evaluates to true *)
is_not_found (Invalid_argument "Invalid arg exn");; (* evaluates to false *)

```
