# Please, I need help

**URL:** <https://discuss.ocaml.org/t/please-i-need-help/5949>\
**Category:** Learning\
**Created:** [June 10, 2020, 4:38pm UTC](https://discuss.ocaml.org/t/please-i-need-help/5949 "2020-06-10T16:38:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![iBlue](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/iblue/32/2233_2.png) [@iBlue](https://discuss.ocaml.org/u/iBlue)\
**Post date:** [June 10, 2020, 4:38pm UTC](https://discuss.ocaml.org/t/please-i-need-help/5949/1 "2020-06-10T16:38:21Z")

</div>

I’m learning Ocaml at school and I got an exam tomorrow but there is something I still don’t understand. I think my code is correct but the problem come from the type of my function, Ocaml return an error saying : Error: This expression has type char but an expression was expected of type string aiming at (str.[i]). The fact is that I want the first function encadree to understand the © is a character but when I define the function Ocaml return : val encadree : string -\> string = instead of : val encadree : char -\> string =   
Do you know if there is anything to define the type of a var by himself, thank’s !

Here is my code :

let encadree © : string = “[”^c^"]";;

let crochete (str) = let rep = ref “” in  
for i = 0 to String.length(str) do  
rep:= !rep^encadree(str.[i])  
done;  
!rep;;

and here is a screen of the exercise if you speak a little of french 🙂

 ![Screenshot_1](https://us1.discourse-cdn.com/flex020/uploads/ocaml/original/2X/9/99a7aae5bdcdd83f8ed729b8024b8ab793564ebf.jpeg)

---

<div class="post-metadata">

**Author:** ![dakk](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dakk/32/2299_2.png) [@dakk](https://discuss.ocaml.org/u/dakk)\
**Post date:** [June 10, 2020, 4:52pm UTC](https://discuss.ocaml.org/t/please-i-need-help/5949/2 "2020-06-10T16:52:28Z")

</div>

> [@iBlue](#):
>
> let encadree © : string = “[”^c^“]”;;

c is a char, and ^ needs two string; you can build a 1-length string with the character c with

`String.make 1 c`, so your encadree becomes

`let encadree (c) : string = “[”^(String.make 1 c)^"]";;`

this way the character is transformed to a string, and encadree signature becomes `char -> string`

(I didn’t check the rest of the code, I don’t understand french; btw please use a meaningful title for the post)

---

<div class="post-metadata">

**Author:** ![bltxd](https://avatars.discourse-cdn.com/v4/letter/b/839c29/32.png) [@bltxd](https://discuss.ocaml.org/u/bltxd)\
**Post date:** [June 10, 2020, 5:15pm UTC](https://discuss.ocaml.org/t/please-i-need-help/5949/3 "2020-06-10T17:15:39Z")

</div>

Unless the intent of theses exercises is to have you deal with references, you might consider using the `Buffer` module. In particular `Buffer.add_char` and `Buffer.contents` could prove useful.

As a side note, you are using too many parentheses: in OCaml `f x y z` is equivalent to `f(x, y, z)` in more common languages. But in OCaml the latter invokes a function whose single argument is a triplet…
