# How to play with first class function in ocaml

**URL:** <https://discuss.ocaml.org/t/how-to-play-with-first-class-function-in-ocaml/943>\
**Category:** Learning\
**Created:** [October 10, 2017, 9:04pm UTC](https://discuss.ocaml.org/t/how-to-play-with-first-class-function-in-ocaml/943 "2017-10-10T21:04:45Z")\
**Posts on this page:** 4\
**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 10, 2017, 9:04pm UTC](https://discuss.ocaml.org/t/how-to-play-with-first-class-function-in-ocaml/943/1 "2017-10-10T21:04:45Z")

</div>

Hi,  
Can any one tell me please tell me how to make simple application with this type of function,  
I want to make this function let doub y x=x\*y as first calss. i know the difinition but i cant understand how to implement it.

type test =  
{  
fonc: (int -\> int) ;  
(\* An argument, which will be given to the function. _)  
arg: int ;  
(_ The expected result. \*)  
expect: int }

---

<div class="post-metadata">

**Author:** ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)\
**Post date:** [October 10, 2017, 11:47pm UTC](https://discuss.ocaml.org/t/how-to-play-with-first-class-function-in-ocaml/943/2 "2017-10-10T23:47:06Z")

</div>

The problem happens when you try to create a value of this record type:

```auto
# type test = { fonc : int -> int; arg : int; expect : int };;
type test = { fonc : int -> int; arg : int; expect : int; }
# let test1 = { fonc = fun x -> x; arg = 1; expect = 1 };;
Error: Unbound value arg

```

This happens because the semi-colon (`;`) is overloaded in OCaml, it means both ‘record member separator’ and ‘sequencing operator’. In this case OCaml is thinking you meant the latter while you really meant the former. To fix this, you’ll need to make OCaml understand that you meant the former, using parentheses:

```auto
# let test1 = { fonc = (fun x -> x); arg = 1; expect = 1 };;
val test1 : test = {fonc = <fun>; arg = 1; expect = 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 11, 2017, 5:02am UTC](https://discuss.ocaml.org/t/how-to-play-with-first-class-function-in-ocaml/943/3 "2017-10-11T05:02:35Z")

</div>

Ok. Thank you, I need to know how to call test in ocaml ???

---

<div class="post-metadata">

**Author:** ![bobbypriambodo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bobbypriambodo/32/179_2.png) [@bobbypriambodo](https://discuss.ocaml.org/u/bobbypriambodo)\
**Post date:** [October 11, 2017, 6:14am UTC](https://discuss.ocaml.org/t/how-to-play-with-first-class-function-in-ocaml/943/4 "2017-10-11T06:14:53Z")

</div>

Given what @yawaramin wrote:

```auto
# test1.fonc test1.arg;;
- : int = 1
# test1.fonc test1.arg = test1.expect;;
- : bool = true

```
